2011-06-14 16:05:12 +00:00
|
|
|
class Artist < ActiveRecord::Base
|
2011-09-26 05:22:18 +00:00
|
|
|
has_many :albums, :conditions => ['has_pic = 1'], :order => 'year ASC', :dependent => :destroy
|
2011-09-20 20:30:42 +00:00
|
|
|
has_many :artist_links, :dependent => :destroy
|
2011-09-21 23:20:41 +00:00
|
|
|
has_many :artist_aliases, :dependent => :destroy
|
|
|
|
has_many :tracks, :through => :track_artists
|
2011-11-26 15:03:33 +00:00
|
|
|
has_many :playlists
|
2011-10-20 11:01:57 +00:00
|
|
|
|
|
|
|
after_initialize :prepare_description
|
|
|
|
|
|
|
|
def status_str
|
|
|
|
%w(loading ok fail)[self.status]
|
|
|
|
end
|
2011-11-15 14:41:51 +00:00
|
|
|
|
|
|
|
def load_again!
|
|
|
|
albums.each(&:destroy)
|
|
|
|
artist_links.each(&:destroy)
|
|
|
|
artist_aliases.each(&:destroy)
|
|
|
|
self.status = 0
|
|
|
|
save!
|
|
|
|
Delayed::Job.enqueue(LoadArtistJob.new(name))
|
|
|
|
end
|
2011-10-29 09:34:53 +00:00
|
|
|
|
|
|
|
private
|
2011-10-20 11:01:57 +00:00
|
|
|
|
|
|
|
def prepare_description
|
2011-10-29 09:34:53 +00:00
|
|
|
self.desc.gsub!(/[\[<].*?[\]>]/, '') unless self.desc.nil?
|
|
|
|
rescue
|
|
|
|
# WTF?!
|
2011-10-20 11:01:57 +00:00
|
|
|
end
|
2011-06-14 16:05:12 +00:00
|
|
|
end
|