class Formulaic::Form

Constants

ATTRIBUTE_INPUT_MAP

Attributes

action[R]
inputs[R]
model_name[R]

Public Class Methods

new(model_name, action, attributes) click to toggle source
# File lib/formulaic/form.rb, line 19
def initialize(model_name, action, attributes)
  @action = action
  @inputs = build_inputs(model_name, attributes)
end

Public Instance Methods

fill() click to toggle source
# File lib/formulaic/form.rb, line 24
def fill
  @inputs.each { |input| input.fill }
end

Private Instance Methods

build_input(model_name, field, value) click to toggle source
# File lib/formulaic/form.rb, line 38
def build_input(model_name, field, value)
  label = Label.new(model_name, field, action)
  input_class_for(value).new(label, value)
end
build_inputs(model_name, attributes) click to toggle source
# File lib/formulaic/form.rb, line 32
def build_inputs(model_name, attributes)
  attributes.map do |field, value|
    build_input(model_name, field, value)
  end
end
input_class_for(value) click to toggle source
# File lib/formulaic/form.rb, line 43
def input_class_for(value)
  ATTRIBUTE_INPUT_MAP.fetch(value.class) do
    raise InvalidAttributeTypeError.new("Formulaic does not know how to fill in a #{value.class} value")
  end
end