Module: Sunrise::Models::Asset::InstanceMethods
- Defined in:
- lib/sunrise/models/asset.rb
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #format_created_at ⇒ Object
- #geometry ⇒ Object
- #has_dimensions? ⇒ Boolean
- #image? ⇒ Boolean
- #thumb_url ⇒ Object
- #to_xml(options = {}, &block) ⇒ Object
Instance Method Details
#as_json(options = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/sunrise/models/asset.rb', line 61 def as_json( = nil) = { :only => [:id, :guid, :assetable_id, :assetable_type, :user_id], :root => 'asset', :methods => [:filename, :url, :size, :content_type, :thumb_url] }.merge( || {}) super end |
#format_created_at ⇒ Object
37 38 39 |
# File 'lib/sunrise/models/asset.rb', line 37 def format_created_at I18n.l(created_at, :format => "%d.%m.%Y %H:%M") end |
#geometry ⇒ Object
79 80 81 82 |
# File 'lib/sunrise/models/asset.rb', line 79 def geometry @geometry ||= Paperclip::Geometry.from_file(data.to_file) @geometry end |
#has_dimensions? ⇒ Boolean
71 72 73 |
# File 'lib/sunrise/models/asset.rb', line 71 def has_dimensions? respond_to?(:width) && respond_to?(:height) end |
#image? ⇒ Boolean
75 76 77 |
# File 'lib/sunrise/models/asset.rb', line 75 def image? Sunrise::Utils::IMAGE_TYPES.include?(content_type) end |
#thumb_url ⇒ Object
33 34 35 |
# File 'lib/sunrise/models/asset.rb', line 33 def thumb_url url(:thumb) end |
#to_xml(options = {}, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sunrise/models/asset.rb', line 41 def to_xml( = {}, &block) = {:only => [:id], :root => 'asset'}.merge() [:procs] ||= Proc.new do |, record| [:builder].tag!('filename', filename) [:builder].tag!('path', url) [:builder].tag!('size', size) unless styles.empty? [:builder].tag!('styles') do |xml| styles.each do |style| xml.tag!(style.first, url(style.first)) end end end end super end |