Class: Handlers::Associates

Inherits:
Base
  • Object
show all
Defined in:
lib/handlers/associates.rb

Instance Method Summary collapse

Methods inherited from Base

handle, #initialize, #raise_error, #upper

Constructor Details

This class inherits a constructor from Handlers::Base

Instance Method Details

#handleObject



6
7
8
9
10
# File 'lib/handlers/associates.rb', line 6

def handle
  (upper('@@associated_forms') || []).each do |form|
    @klass.instance_variable_set("@#{form[:name]}_form", form[:form])
  end
end

#save_associated_forms!Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/handlers/associates.rb', line 12

def save_associated_forms!
  (upper('@@associated_forms') || []).each do |associated|
    params = associated[:params].nil? ? @params[associated[:name]] : @klass.send(associated[:params])
    resource_to_save = @klass.send("#{associated[:name]}_to_update") rescue nil
    the_form = associated[:form]

    saved_form = the_form.new(params, resource_to_save).save!
    @klass.instance_variable_set("@#{associated[:name]}", saved_form)
  end
end