Skip to content

Instantly share code, notes, and snippets.

@Creagency
Created December 1, 2009 01:10
Show Gist options
  • Save Creagency/245962 to your computer and use it in GitHub Desktop.
Save Creagency/245962 to your computer and use it in GitHub Desktop.
class Playlist < AR::Base
belongs_to :owner, :class_name => 'User'
end
class DefaultPlaylist < Playlist
def name
"On the go"
end
end
class VirtualPlaylist < Playlist
Track_limit = 50
attr_accessor :mode
serilize :track_ids
def tracks
refresh! unless track_ids
Track.all(:conditions => {:id=> track_ids})
end
def refresh!
case mode
when :recent
self.track_ids = Activity.played(
:select => 'target_id',
:include => :target,
:conditions => { :target_type => 'played'},
:limit => Track_limit,
:group => 'target_type, target_id'
).map(&:target_id)
when :favourite
when :popular
end
self.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment