class Formalist::Form

Attributes

definition[R]
dependencies[R]
elements[R]
errors[R]
input[R]

Public Class Methods

define(&block) click to toggle source
# File lib/formalist/form.rb, line 16
def define(&block)
  @definition = block
end
new(elements: Undefined, input: {}, errors: {}, **dependencies) click to toggle source
# File lib/formalist/form.rb, line 26
def initialize(elements: Undefined, input: {}, errors: {}, **dependencies)
  @input = input
  @errors = errors

  @elements =
    if elements == Undefined
      Definition.new(self, self.class.config, &self.class.definition).elements
    else
      elements
    end

  @dependencies = dependencies
end

Public Instance Methods

fill(input: {}, errors: {}) click to toggle source
# File lib/formalist/form.rb, line 40
def fill(input: {}, errors: {})
  return self if input == @input && errors == @errors

  self.class.new(
    elements: @elements.map { |element| element.fill(input: input, errors: errors) },
    input: input,
    errors: errors,
    **@dependencies,
  )
end
to_ast() click to toggle source
# File lib/formalist/form.rb, line 60
def to_ast
  elements.map(&:to_ast)
end
with(**new_dependencies) click to toggle source
# File lib/formalist/form.rb, line 51
def with(**new_dependencies)
  self.class.new(
    elements: @elements,
    input: @input,
    errors: @errors,
    **@dependencies.merge(new_dependencies)
  )
end