app/models/concerns/polygallery/acts_as_polyphoto.rb in polygallery-0.1.8 vs app/models/concerns/polygallery/acts_as_polyphoto.rb in polygallery-0.1.9
- old
+ new
@@ -11,10 +11,12 @@
module ClassMethods
def acts_as_polyphoto(options={})
defaults = self.polygallery_settings
settings = defaults.deep_merge(options)
+ init_attachment settings[:paperclip]
+
after_initialize do
@polygallery_settings = settings if settings == HasPolygallery::DEFAULTS
self.initialize_polyphoto
end
@@ -22,10 +24,21 @@
end
def polygallery_settings
@polygallery_settings || HasPolygallery::DEFAULTS
end
+
+ def init_attachment(paperclip_settings)
+ has_attached_file :photo,
+ :styles => paperclip_settings[:styles],
+ :default_url => paperclip_settings[:default_url]
+ validations = polygallery_settings[:paperclip_validations]
+ validates_attachment_content_type(:photo, :content_type =>
+ validations[:content_type]) if validations[:content_type]
+ validates_attachment_presence(:photo) if validations[:presence]
+ end
+
end
module LocalInstanceMethods
def include_polygallery_settings(settings)
@polygallery_settings = settings
@@ -64,16 +77,10 @@
def process_photo_to_upload
self.photo = File.open(photo_to_upload) if photo_to_upload.present?
end
def init_attachment
- self.class.has_attached_file :photo,
- :styles => paperclip_settings[:styles],
- :default_url => paperclip_settings[:default_url]
- validations = polygallery_settings[:paperclip_validations]
- self.class.validates_attachment_content_type(:photo, :content_type =>
- validations[:content_type]) if validations[:content_type]
- self.class.validates_attachment_presence(:photo) if validations[:presence]
+ self.class.init_attachment paperclip_settings
end
end
end
end