class Rectify::BuildFormFromModel

Attributes

form_class[R]
model[R]

Public Class Methods

new(form_class, model) click to toggle source
# File lib/rectify/build_form_from_model.rb, line 3
def initialize(form_class, model)
  @form_class = form_class
  @model = model
end

Public Instance Methods

build() click to toggle source
# 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

Private Instance Methods

attribute_set() click to toggle source
# File lib/rectify/build_form_from_model.rb, line 27
def attribute_set
  form_class.attribute_set
end
form() click to toggle source
# File lib/rectify/build_form_from_model.rb, line 23
def form
  @form ||= form_class.new
end
matching_attributes() click to toggle source
# File lib/rectify/build_form_from_model.rb, line 31
def matching_attributes
  attribute_set
    .select { |a| model.respond_to?(a.name) }
    .map    { |a| FormAttribute.new(a) }
end