Class: Formalist::Form::Result::Section
- Inherits:
-
Object
- Object
- Formalist::Form::Result::Section
- Defined in:
- lib/formalist/form/result/section.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize(definition, input, rules, errors) ⇒ Section
constructor
A new instance of Section.
-
#to_ast ⇒ Array
Converts the section into an array format for including in a form's abstract syntax tree.
Constructor Details
#initialize(definition, input, rules, errors) ⇒ Section
Returns a new instance of Section.
8 9 10 11 12 13 14 |
# File 'lib/formalist/form/result/section.rb', line 8 def initialize(definition, input, rules, errors) @definition = definition @input = input @rules = rules @errors = errors @children = definition.children.map { |el| el.(input, rules, errors) } end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/formalist/form/result/section.rb', line 6 def children @children end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
5 6 7 |
# File 'lib/formalist/form/result/section.rb', line 5 def definition @definition end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/formalist/form/result/section.rb', line 5 def errors @errors end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
5 6 7 |
# File 'lib/formalist/form/result/section.rb', line 5 def input @input end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
5 6 7 |
# File 'lib/formalist/form/result/section.rb', line 5 def rules @rules end |
Instance Method Details
#to_ast ⇒ Array
Converts the section into an array format for including in a form's abstract syntax tree.
The array takes the following format:
[:section, [params]]
With the following parameters:
- Section name
- Section configuration
- Child form elements
44 45 46 47 48 49 50 |
# File 'lib/formalist/form/result/section.rb', line 44 def to_ast [:section, [ definition.name, definition.config.to_a, children.map(&:to_ast), ]] end |