Player library, unified renderer for artists and playlists

This commit is contained in:
magnolia-fan
2011-11-27 16:37:51 +04:00
parent 453e809646
commit 9ec28708c5
23 changed files with 174 additions and 122 deletions
+9
View File
@@ -9,4 +9,13 @@ class Album < ActiveRecord::Base
def self.with_format f
joins(:release_formats).where(:release_formats => { :hash => f.to_s })
end
def serialize
{
name: name,
pic_url: pic_url,
year: year,
tracks: tracks.map(&:serialize)
}
end
end
+9
View File
@@ -19,6 +19,15 @@ class Artist < ActiveRecord::Base
save!
Delayed::Job.enqueue(LoadArtistJob.new(name))
end
def serialize
{
name: name,
pic_url: pic_url,
desc: desc,
albums: albums.map(&:serialize)
}
end
private
+14
View File
@@ -14,4 +14,18 @@ class Track < ActiveRecord::Base
'0:00'
end
end
def serialize
{
id: id,
artist: artists.first.name,
album: album.name,
position: position.to_s(36),
name: name,
length: length,
duration: duration,
available: available,
album_pic: album.pic_url
}
end
end