Class: MusicVideo

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Likeable
Defined in:
app/models/music_video.rb

Constant Summary collapse

STATUSES =
%w(Official Unofficial Live)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.order_by_statusObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/music_video.rb', line 44

def self.order_by_status
  if Rails.env.production?
    order_by = ["case"]
    
    STATUSES.each_with_index.map do |status, index|
      order_by << "WHEN status='#{status}' THEN #{index}"
    end
    
    order_by << "end"
    order(order_by.join(" "))
  else
    order("FIELD(status, '#{STATUSES.join("','")}')")
  end
end

Instance Method Details

#nameObject



59
60
61
# File 'app/models/music_video.rb', line 59

def name
  "#{track.artist_name }#{track_name} (#{status})"
end

#to_jsonObject



63
64
65
66
67
68
# File 'app/models/music_video.rb', line 63

def to_json
  { 
    id: id, status: status, artist_id: artist_id, artist_name: artist_name, 
    track_id: track_id, track_name: track_name, url: url
  } 
end