Class: Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Asset
- Defined in:
- app/models/asset.rb
Constant Summary collapse
- AUDIO_FORMATS =
HACK: incomplete
[:wav, :mp3, :m4a, :ogg]
- VIDEO_FORMATS =
[:mp4, :avi]
Instance Method Summary collapse
- #audio? ⇒ Boolean
- #format ⇒ Object
- #image? ⇒ Boolean
- #page_attachments ⇒ Object
- #to_s ⇒ Object
- #uploads ⇒ Object
- #uploads=(new_uploads) ⇒ Object
- #video? ⇒ Boolean
Instance Method Details
#audio? ⇒ Boolean
46 47 48 |
# File 'app/models/asset.rb', line 46 def audio? AUDIO_FORMATS.include?(format) end |
#format ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/models/asset.rb', line 29 def format # HACK: relying on extension instead of using analyser and upload.format # analyser can throw us into very long loop when trying to identify # non-image files like word docs upload.ext ? upload.ext.to_sym : :generic rescue Dragonfly::FunctionManager::UnableToHandle :generic end |
#image? ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'app/models/asset.rb', line 38 def image? # PDF is listed as supported by imagemagick but thumbnailing etc. doesn't # work reliably so we treat it as a non-image return false if format == :pdf image_formats = Dragonfly::Encoding::ImageMagickEncoder.new.supported_formats image_formats.include?(format) end |
#page_attachments ⇒ Object
13 14 15 |
# File 'app/models/asset.rb', line 13 def .select(&:attached_to_page?) end |
#to_s ⇒ Object
54 55 56 |
# File 'app/models/asset.rb', line 54 def to_s || upload.name || '' end |
#uploads ⇒ Object
17 18 19 |
# File 'app/models/asset.rb', line 17 def uploads [] end |
#uploads=(new_uploads) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/models/asset.rb', line 21 def uploads=(new_uploads) # HACK: depends on javascript being present and packaging each file # in its own request # TODO: handle non-js situations with several files in one request # see Admin::AttachmentsController#create and Admin::AssetsController#create self.upload = Array(new_uploads).first end |
#video? ⇒ Boolean
50 51 52 |
# File 'app/models/asset.rb', line 50 def video? VIDEO_FORMATS.include?(format) end |