Module: Polygallery::ActsAsPolyphoto::ClassMethods

Defined in:
app/models/concerns/polygallery/acts_as_polyphoto.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_polyphoto(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 9

def acts_as_polyphoto(options={})
  defaults = self.polygallery_settings
  settings = defaults.deep_merge(options)

  attr_accessor :photo_to_upload, :polygallery_options
  
  init_attachment settings[:paperclip]
  init_associations settings

  after_initialize do
    self.polygallery_options ||= self.polygallery_settings
    self.initialize_polyphoto
  end

  include ActsAsPolyphoto::LocalInstanceMethods
end

#init_associations(settings = HasPolygallery::DEFAULTS) ⇒ Object



43
44
45
46
47
48
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 43

def init_associations(settings=HasPolygallery::DEFAULTS)
  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



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 30

def init_attachment(paperclip_settings)
  has_attached_file :photo,
    :styles => ->(a) {
        a.instance.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]

  before_validation :process_photo_to_upload
end

#polygallery_settingsObject



26
27
28
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 26

def polygallery_settings
  HasPolygallery::DEFAULTS
end