Class: Locomotive::ContentAsset
- Inherits:
-
Object
- Object
- Locomotive::ContentAsset
- Includes:
- ActionView::Helpers::NumberHelper, Locomotive::Concerns::Asset::Checksum, Locomotive::Concerns::Asset::Types, Locomotive::Concerns::Asset::Vignette, Mongoid::Document
- Defined in:
- app/models/locomotive/content_asset.rb
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
-
#content_type ⇒ Object
fields ##.
- #extname ⇒ Object
- #maximum_file_size ⇒ Object
-
#ordered ⇒ Object
scopes ##.
-
#site ⇒ Object
associations ##.
-
#source ⇒ Object
behaviours ##.
Methods included from Locomotive::Concerns::Asset::Vignette
#alternative_vignette_url, #big_vignette_url, #vignette_url
Instance Method Details
#as_json(options = nil) ⇒ Object
43 44 45 46 47 48 |
# File 'app/models/locomotive/content_asset.rb', line 43 def as_json( = nil) super.merge( thumbnail_url: self.big_vignette_url, size_to_human: number_to_human_size(self.size) ) end |
#content_type ⇒ Object
fields ##
13 |
# File 'app/models/locomotive/content_asset.rb', line 13 field :content_type, type: String |
#extname ⇒ Object
38 39 40 41 |
# File 'app/models/locomotive/content_asset.rb', line 38 def extname return nil unless self.source? && self.source_filename File.extname(self.source_filename).gsub(/^\./, '') end |
#maximum_file_size ⇒ Object
50 51 52 |
# File 'app/models/locomotive/content_asset.rb', line 50 def maximum_file_size errors.add(:source, :maximum_file_size_exceeded) if size_changed? && size > site.maximum_uploaded_file_size end |
#ordered ⇒ Object
scopes ##
30 |
# File 'app/models/locomotive/content_asset.rb', line 30 scope :ordered, -> { order_by(created_at: :desc) } |
#site ⇒ Object
associations ##
20 |
# File 'app/models/locomotive/content_asset.rb', line 20 belongs_to :site, class_name: 'Locomotive::Site', validate: false, autosave: false |
#source ⇒ Object
behaviours ##
23 |
# File 'app/models/locomotive/content_asset.rb', line 23 validates_presence_of :source |