atzorvas/ccradio

View on GitHub
app/models/playlist_item.rb

Summary

Maintainability
A
0 mins
Test Coverage
Missing top-level class documentation comment.
class PlaylistItem < ActiveRecord::Base
belongs_to :stream
validates :song, uniqueness: true, unless: :last_song_differs
after_create :notify
 
def notify
Do not introduce global variables.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
$redis.publish "songs", { song: self }.to_json
end
 
def last_song_differs
stream.playlist_items.any? &&
song != stream.playlist_items.last.song
end
end