feature/share-libs
rb 39 lines 667 Bytes
Raw
1 require 'action_view'
2 require 'action_view/helpers'
3
4 class AlbumProvider < ApplicationRecord
5 include ActionView::Helpers::DateHelper
6 include Rails.application.routes.url_helpers
7
8 belongs_to :user
9 belongs_to :album
10
11 enum provider_type: %i[
12 spotify
13 ]
14
15 def as_json(options = {})
16 options[:methods] = %i[path type created]
17 super
18 end
19
20 def type
21 I18n.t(self.class.name)
22 end
23
24 def slug
25 "#{name}-#{id}".downcase.parameterize
26 end
27
28 def path
29 album_bridge_path(slug)
30 end
31
32 def provider_url
33 "https://open.spotify.com/album/#{provider_id}"
34 end
35
36 def created
37 "#{time_ago_in_words(created_at)} #{I18n.t('ago')}"
38 end
39 end