diff options
Diffstat (limited to 'app/models/asset.rb')
| -rw-r--r-- | app/models/asset.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/asset.rb b/app/models/asset.rb index aca0ee8..4a295d8 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb | |||
| @@ -1,12 +1,22 @@ | |||
| 1 | class Asset < ApplicationRecord | 1 | class Asset < ApplicationRecord |
| 2 | IMAGE_CONTENT_TYPES = ["image/gif", "image/jpeg", "image/png", "image/webp"] | ||
| 2 | 3 | ||
| 3 | include FileAttachment | 4 | include FileAttachment |
| 4 | 5 | ||
| 5 | has_many :related_assets, :dependent => :destroy | 6 | has_many :related_assets, :dependent => :destroy |
| 6 | has_many :pages, :through => :related_assets | 7 | has_many :pages, :through => :related_assets |
| 7 | 8 | ||
| 8 | scope :images, -> { where(:upload_content_type => ["image/gif", "image/jpeg", "image/png", "image/webp"]) } | 9 | scope :images, -> { where(:upload_content_type => IMAGE_CONTENT_TYPES) } |
| 9 | scope :documents, -> { where(:upload_content_type => ["application/pdf", "text/plain", "text/rtf"]) } | 10 | scope :documents, -> { where(:upload_content_type => ["application/pdf", "text/plain", "text/rtf"]) } |
| 10 | scope :audio, -> { where(:upload_content_type => ["audio/mpeg", "audio/x-m4a", "audio/wav", "audio/x-wav"]) } | 11 | scope :audio, -> { where(:upload_content_type => ["audio/mpeg", "audio/x-m4a", "audio/wav", "audio/x-wav"]) } |
| 11 | 12 | ||
| 13 | validates :license_key, inclusion: { in: -> { AssetLicense.keys } }, allow_blank: true | ||
| 14 | |||
| 15 | def image? | ||
| 16 | IMAGE_CONTENT_TYPES.include?(upload_content_type) | ||
| 17 | end | ||
| 18 | |||
| 19 | def has_credit? | ||
| 20 | creator.present? || source_url.present? || license_key.present? | ||
| 21 | end | ||
| 12 | end | 22 | end |
