Class: Transit::Asset

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps, Paperclip::Glue
Defined in:
app/models/transit/asset.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.asset_config_with_defaultObject



25
26
27
28
29
30
# File 'app/models/transit/asset.rb', line 25

def self.asset_config_with_default
  styles = Transit::Config.assets
  return styles unless styles[:styles].present?
  styles[:styles].reverse_merge!(preview: '50x50#')
  styles
end

Instance Method Details

#file_urlsObject

Provide a way to get a list of all urls for the attachment



41
42
43
44
# File 'app/models/transit/asset.rb', line 41

def file_urls
  return { :original => file.url(:original) } unless image?
  file.styles.keys.inject({}){ |hash, style|  hash.merge!(style => file.url(style)) }
end

#image?Boolean

Determine if this asset is an image

Returns:

  • (Boolean)


36
37
38
# File 'app/models/transit/asset.rb', line 36

def image?
  (self.file_content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$})
end

#skip_processing_unless_imageObject



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

def skip_processing_unless_image
  if !(file.content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$})
    return false 
  end
end

#timestampObject



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

def timestamp
  self.created_at.strftime("%B %d, %Y")
end