Class: Rectify::BuildFormFromModel

Inherits:
Object
  • Object
show all
Defined in:
lib/rectify/build_form_from_model.rb

Instance Method Summary collapse

Constructor Details

#initialize(form_class, model) ⇒ BuildFormFromModel

Returns a new instance of BuildFormFromModel.



3
4
5
6
# File 'lib/rectify/build_form_from_model.rb', line 3

def initialize(form_class, model)
  @form_class = form_class
  @model = model
end

Instance Method Details

#buildObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/rectify/build_form_from_model.rb', line 8

def build
  form.tap do
    matching_attributes.each do |a|
      model_value = model.public_send(a.name)
      form.public_send("#{a.name}=", a.value_from(model_value))
    end

    form.map_model(model)
  end
end