Module: Griddle::HasGridAttachment::ClassMethods

Defined in:
lib/griddle/has_grid_attachment.rb

Instance Method Summary collapse

Instance Method Details

#attachment_definitionsObject



27
28
29
# File 'lib/griddle/has_grid_attachment.rb', line 27

def attachment_definitions
  read_inheritable_attribute(:attachment_definitions)
end

#has_grid_attachment(name, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/griddle/has_grid_attachment.rb', line 11

def has_grid_attachment name, options = {}
  write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
  attachment_definitions[name] = options

  after_save :save_attached_files if respond_to? :after_save
  after_destroy :destroy_attached_files if respond_to? :after_destroy
  
  define_method(name) do |*args|
    attachment_for(name, options)
  end
  
  define_method("#{name}=") do |file|
    attachment_for(name, options).assign(file)
  end        
end