Class: Formalist::Elements::Attr
- Inherits:
-
Formalist::Element
- Object
- Formalist::Element
- Formalist::Elements::Attr
- Defined in:
- lib/formalist/elements/attr.rb
Instance Attribute Summary
Attributes inherited from Formalist::Element
#attributes, #children, #errors, #input, #name
Instance Method Summary collapse
- #fill(input:, errors:) ⇒ Object
-
#to_ast ⇒ Array
Converts the attribute into an abstract syntax tree.
Methods inherited from Formalist::Element
#==, build, fill, #initialize, #type
Methods included from Formalist::Element::ClassInterface
#attribute, #attributes_schema, #type
Constructor Details
This class inherits a constructor from Formalist::Element
Instance Method Details
#fill(input:, errors:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/formalist/elements/attr.rb', line 8 def fill(input:, errors:) input = input[name] || {} errors = errors[name] || {} children = self.children.map { |child| child.fill(input: input, errors: errors) } super(input: input, errors: errors, children: children) end |
#to_ast ⇒ Array
Converts the attribute into an abstract syntax tree.
It takes the following format:
[:attr, [params]]
With the following parameters:
- Attribute name
- Custom element type (or
:attrotherwise) - Error messages
- Form element attributes
- Child form elements
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/formalist/elements/attr.rb', line 48 def to_ast local_errors = errors.is_a?(Array) ? errors : [] [:attr, [ name, type, local_errors, Element::Attributes.new(attributes).to_ast, children.map(&:to_ast), ]] end |