Module: FreeForm::Model::ClassMethods

Defined in:
lib/freeform/form/model.rb

Instance Method Summary collapse

Instance Method Details

#child_model(name, opts = {}, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/freeform/form/model.rb', line 31

def child_model(name, opts={}, &block)
  declared_model(name)
  @child_models = (@child_models || []) << name

  # Defines an initializer method, such as 'initialize_address' 
  #  that can be called on form initialization to build the model
  define_method("initialize_#{name}") do
    instance_variable_set("@#{name}", instance_eval(&block))
  end
end

#child_modelsObject



14
15
16
# File 'lib/freeform/form/model.rb', line 14

def child_models
  @child_models ||= []
end

#declared_model(name, opts = {}) ⇒ Object Also known as: form_model



25
26
27
28
# File 'lib/freeform/form/model.rb', line 25

def declared_model(name, opts={})
  attr_accessor name
  @models = (@models || []) << name
end

#declared_models(*names) ⇒ Object Also known as: form_models



18
19
20
21
22
# File 'lib/freeform/form/model.rb', line 18

def declared_models(*names)
  names.each do |name|
    declared_model(name)
  end
end

#modelsObject



10
11
12
# File 'lib/freeform/form/model.rb', line 10

def models
  @models ||= []
end