Module: Polygallery::HasPolyphotos::ClassMethods

Defined in:
lib/polygallery/has_polyphotos.rb

Instance Method Summary collapse

Instance Method Details

#has_polyphotos(title = nil, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/polygallery/has_polyphotos.rb', line 9

def has_polyphotos(title=nil, options={})
  attr_accessor :polygallery_options

  defaults = self.polygallery_settings
  association_names = (options[:association_names].present? ? 
                       options : defaults)[:association_names]
  title ||= association_names[:photos].to_s
  if title.is_a? Hash
    options = title
    title = association_names[:photos].to_s
  end

  settings = defaults.deep_merge options
  init_associations settings

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

  include HasPolyphotos::LocalInstanceMethods
end

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



36
37
38
39
40
41
42
# File 'lib/polygallery/has_polyphotos.rb', line 36

def init_associations(settings=HasPolygallery::DEFAULTS)
  belongs_to :galleryable, :polymorphic => true
  photos_name = settings[:association_names][:photos]
  has_many photos_name, settings[:associations][:photos]
  accepts_nested_attributes_for photos_name,
      settings[:nested_attributes][:photos]
end

#polygallery_settingsObject



32
33
34
# File 'lib/polygallery/has_polyphotos.rb', line 32

def polygallery_settings
  HasPolygallery::DEFAULTS
end