Class: Asset

Inherits:
ActiveRecord::Base
  • Object
show all
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

Instance Method Details

#audio?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/asset.rb', line 46

def audio?
  AUDIO_FORMATS.include?(format)
end

#formatObject



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

Returns:

  • (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_attachmentsObject



13
14
15
# File 'app/models/asset.rb', line 13

def page_attachments
  attachments.select(&:attached_to_page?)
end

#to_sObject



54
55
56
# File 'app/models/asset.rb', line 54

def to_s
  caption || upload.name || ''
end

#uploadsObject



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

Returns:

  • (Boolean)


50
51
52
# File 'app/models/asset.rb', line 50

def video?
  VIDEO_FORMATS.include?(format)
end