Module: Reform::Form::Composition

Defined in:
lib/reform/form/composition.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Automatically creates a Composition object for you when initializing the form.



5
6
7
8
9
10
# File 'lib/reform/form/composition.rb', line 5

def self.included(base)
  base.class_eval do
    extend Reform::Form::ActiveModel::ClassMethods # ::model.
    extend ClassMethods
  end
end

Instance Method Details

#aliased_modelObject

we don’t need an Expose as we save the Composition instance in the constructor.



62
63
64
# File 'lib/reform/form/composition.rb', line 62

def aliased_model # we don't need an Expose as we save the Composition instance in the constructor.
  model
end

#initialize(models) ⇒ Object



57
58
59
60
# File 'lib/reform/form/composition.rb', line 57

def initialize(models)
  composition = self.class.model_class.new(models)
  super(composition)
end

#to_hash(*args) ⇒ Object



70
71
72
# File 'lib/reform/form/composition.rb', line 70

def to_hash(*args)
  mapper.new(self).to_hash(*args)
end

#to_nested_hashObject



66
67
68
# File 'lib/reform/form/composition.rb', line 66

def to_nested_hash
  model.nested_hash_for(to_hash)  # use composition to compute nested hash.
end