Module: FreeForm::Model::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

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



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

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



16
17
18
# File 'lib/freeform/form/model.rb', line 16

def child_models
  @child_models ||= []
end

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



27
28
29
30
# File 'lib/freeform/form/model.rb', line 27

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

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



20
21
22
23
24
# File 'lib/freeform/form/model.rb', line 20

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

#modelsObject



12
13
14
# File 'lib/freeform/form/model.rb', line 12

def models
  @models ||= []
end