Class: Stall::Checkout::StepForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/stall/checkout/step_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, step) ⇒ StepForm

Returns a new instance of StepForm.



12
13
14
15
# File 'lib/stall/checkout/step_form.rb', line 12

def initialize(object, step)
  @object = object
  @step = step
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



30
31
32
33
34
35
36
37
38
# File 'lib/stall/checkout/step_form.rb', line 30

def method_missing(method, *args, &block)
  if object.respond_to?(method, true)
    object.send(method, *args, &block)
  elsif step.respond_to?(method, true)
    step.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



8
9
10
# File 'lib/stall/checkout/step_form.rb', line 8

def object
  @object
end

#stepObject (readonly)

Returns the value of attribute step.



8
9
10
# File 'lib/stall/checkout/step_form.rb', line 8

def step
  @step
end

Class Method Details

.build(&block) ⇒ Object



26
27
28
# File 'lib/stall/checkout/step_form.rb', line 26

def self.build(&block)
  Class.new(StepForm, &block)
end

.nested(type, &block) ⇒ Object



21
22
23
24
# File 'lib/stall/checkout/step_form.rb', line 21

def self.nested(type, &block)
  self.nested_forms ||= {}
  nested_forms[type] = build(&block)
end

Instance Method Details

#model_nameObject

Override model name instanciation to add a name, since the form classes are anonymous, and ActiveModel::Name does not support unnamed classes



42
43
44
# File 'lib/stall/checkout/step_form.rb', line 42

def model_name
  @model_name ||= ActiveModel::Name.new(self, nil, object.class.name)
end

#validateObject



17
18
19
# File 'lib/stall/checkout/step_form.rb', line 17

def validate
  super && validate_nested_forms
end