engine/app/models/asset.rb

38 lines
752 B
Ruby
Raw Normal View History

class Asset
2010-05-12 00:16:39 +00:00
include Mongoid::Document
include Mongoid::Timestamps
## extensions ##
include Extensions::Asset::Types
include Extensions::Asset::Vignette
2010-05-12 00:16:39 +00:00
## fields ##
field :content_type, :type => String
field :width, :type => Integer
field :height, :type => Integer
field :size, :type => Integer
field :position, :type => Integer, :default => 0
mount_uploader :source, AssetUploader
2010-05-12 00:16:39 +00:00
## associations ##
2011-06-17 21:32:54 +00:00
referenced_in :site
2010-05-12 00:16:39 +00:00
## validations ##
2011-06-17 21:32:54 +00:00
validates_presence_of :source
## behaviours ##
2010-05-12 00:16:39 +00:00
## methods ##
def extname
return nil unless self.source?
File.extname(self.source_filename).gsub(/^\./, '')
end
def to_liquid
{ :url => self.source.url }.merge(self.attributes).stringify_keys
end
end