Class: Erector::Rails::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/erector/rails/form_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_name, object, template, options, proc) ⇒ FormBuilder

Returns a new instance of FormBuilder


16
17
18
19
# File 'lib/erector/rails/form_builder.rb', line 16

def initialize(object_name, object, template, options, proc)
  @template = template
  @parent = parent_builder_class.new(object_name, object, template, options, proc)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/erector/rails/form_builder.rb', line 21

def method_missing(method_name, *args, &block)
  if parent.respond_to?(method_name)
    return_value = parent.send(method_name, *args, &block)
    if return_value.is_a?(String)
      template.concat(return_value)
      nil
    else
      return_value
    end
  else
    super
  end
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent


14
15
16
# File 'lib/erector/rails/form_builder.rb', line 14

def parent
  @parent
end

#templateObject (readonly)

Returns the value of attribute template


14
15
16
# File 'lib/erector/rails/form_builder.rb', line 14

def template
  @template
end

Class Method Details

.wrapping(parent_builder_class) ⇒ Object


7
8
9
10
11
12
# File 'lib/erector/rails/form_builder.rb', line 7

def self.wrapping(parent_builder_class)
  return self if parent_builder_class.nil?
  Class.new(self).tap do |klass|
    klass.parent_builder_class = parent_builder_class
  end
end