Created
June 30, 2011 10:19
-
-
Save mwawrusch/1055970 to your computer and use it in GitHub Desktop.
child
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReferencedImage | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include SimpleWorker::UsedInWorker | |
IMAGE_TYPES = %w[screenshot artwork thumbnail] | |
# userstamps! | |
# Fields ::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
# Optional source url where this image was derived from, if cached locally | |
field :source_url | |
field :image_type | |
field :import_source, :type => Array , :default => [] | |
# Validations ::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
validates_presence_of :image_type | |
# validates_inclusion_of :image_type, :in => IMAGE_TYPES | |
# Assocations ::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
# composition of different image formats | |
embeds_many :formats , :class_name => "ImageFormat" ,:inverse_of => :referenced_image | |
embedded_in :image_owner, :inverse_of => :images | |
# Creator | |
referenced_in :creator, :class_name => "User", :foreign_key => :creator_id, :validate => false, \ | |
:inverse_of => "created_referenced_images" | |
def large_url | |
large[0] if large | |
end | |
def large | |
l = (formats || []).select {|x| x.format_tag == :large} | |
return l[0].url,l[0].size_w,l[0].size_h if l && l.length > 0 | |
# should find largest format here, or maybe look in some range first | |
return formats[0].url,formats[0].size_w,formats[0].size_h if formats && formats.length > 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment