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

#initialize(models) ⇒ Object



40
41
42
43
# File 'lib/reform/form/composition.rb', line 40

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

#to_hash(*args) ⇒ Object



49
50
51
# File 'lib/reform/form/composition.rb', line 49

def to_hash(*args)
  mapper.new(fields).to_hash(*args) # do not map names, yet. this happens in #to_nested_hash
end

#to_nested_hashObject



45
46
47
# File 'lib/reform/form/composition.rb', line 45

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