Module: Polygallery::ActsAsPolyphoto::ClassMethods
- Defined in:
- lib/polygallery/acts_as_polyphoto.rb
Instance Method Summary collapse
- #acts_as_polyphoto(options = {}) ⇒ Object
- #init_associations(settings = DEFAULT_SETTINGS) ⇒ Object
- #init_attachment(paperclip_settings) ⇒ Object
- #polygallery_settings ⇒ Object
Instance Method Details
#acts_as_polyphoto(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/polygallery/acts_as_polyphoto.rb', line 7 def acts_as_polyphoto(={}) defaults = self.polygallery_settings settings = defaults.deep_merge() attr_accessor :photo_to_upload, :polygallery_options, :polyphoto_initialized attr_reader :photo_remote_url settings[:paperclip] init_associations settings before_validation do # self.polygallery_options = nil # self.polygallery_options = self.polygallery_settings # self.class.init_attachment self.polygallery_options if gallery.present? self.gallery_title = gallery.title if gallery_title.blank? self.galleryable ||= gallery.galleryable initialize_polyphoto end process_photo_to_upload end # before_save { # # puts "Photo changes: #{self.changes.inspect}" # puts 'SAVING PHOTO!' } after_initialize do self. ||= self.polygallery_settings self.initialize_polyphoto end include ActsAsPolyphoto::LocalInstanceMethods end |
#init_associations(settings = DEFAULT_SETTINGS) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/polygallery/acts_as_polyphoto.rb', line 56 def init_associations(settings=DEFAULT_SETTINGS) belongs_to settings[:association_names][:gallery], :class_name => settings[:associations][:gallery][:class_name], :foreign_key => :gallery_id belongs_to :galleryable, :polymorphic => true end |
#init_attachment(paperclip_settings) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/polygallery/acts_as_polyphoto.rb', line 45 def (paperclip_settings) has_attached_file :photo, :styles => ->(a) { a.instance.paperclip_settings[:styles] }, :default_url => paperclip_settings[:default_url] validations = polygallery_settings[:paperclip_validations] (:photo, :content_type => validations[:content_type]) if validations[:content_type] (:photo) if validations[:presence] end |
#polygallery_settings ⇒ Object
41 42 43 |
# File 'lib/polygallery/acts_as_polyphoto.rb', line 41 def polygallery_settings DEFAULT_SETTINGS end |