class Formalist::Element
Attributes
attributes[R]
@api private
children[R]
@api private
errors[R]
@api private
input[R]
@api private
name[R]
@api private
Public Class Methods
build(**args)
click to toggle source
@api private
# File lib/formalist/element.rb, line 12 def self.build(**args) new(**args) end
fill(input: {}, errors: {}, **args)
click to toggle source
@api private
# File lib/formalist/element.rb, line 17 def self.fill(input: {}, errors: {}, **args) new(**args).fill(input: input, errors: errors) end
new(name: nil, attributes: {}, children: [], input: nil, errors: [])
click to toggle source
@api private
# File lib/formalist/element.rb, line 22 def initialize(name: nil, attributes: {}, children: [], input: nil, errors: []) @name = name&.to_sym @attributes = self.class.attributes_schema.each_with_object({}) { |(name, defn), hsh| value = attributes.fetch(name) { defn[:default] } hsh[name] = value unless value.nil? } @children = children @input = input @errors = errors end
Public Instance Methods
==(other)
click to toggle source
# File lib/formalist/element.rb, line 53 def ==(other) name && type == other.type && name == other.name end
fill(input: {}, errors: {}, **args)
click to toggle source
# File lib/formalist/element.rb, line 35 def fill(input: {}, errors: {}, **args) return self if input == @input && errors == @errors args = { name: @name, attributes: @attributes, children: @children, input: input, errors: errors, }.merge(args) self.class.new(**args) end
to_ast()
click to toggle source
@abstract
# File lib/formalist/element.rb, line 58 def to_ast raise NotImplementedError end
type()
click to toggle source
# File lib/formalist/element.rb, line 49 def type self.class.type end