Class: Formalist::Form::Result::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/formalist/form/result/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, input, rules, errors) ⇒ Group

Returns a new instance of Group.



8
9
10
11
12
13
14
# File 'lib/formalist/form/result/group.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/group.rb', line 6

def children
  @children
end

#definition ⇒ Object (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/formalist/form/result/group.rb', line 5

def definition
  @definition
end

#errors ⇒ Object (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/formalist/form/result/group.rb', line 5

def errors
  @errors
end

#input ⇒ Object (readonly)

Returns the value of attribute input.



5
6
7
# File 'lib/formalist/form/result/group.rb', line 5

def input
  @input
end

Instance Method Details

#to_ast ⇒ Array

Converts the group into an array format for including in a form's abstract syntax tree.

The array takes the following format:

[:group, [params]]

With the following parameters:

  1. Group configuration
  2. Child form elements

Examples:

group.to_ast # =>
# [:group, [
#   [
#     [:some_config_name, :some_config_value]
#   ],
#   [
#     ...child elements...
#   ]
# ]]

Returns:

  • (Array) —

    the group as an array.



42
43
44
45
46
47
# File 'lib/formalist/form/result/group.rb', line 42

def to_ast
  [:group, [
    definition.config.to_a,
    children.map(&:to_ast),
  ]]
end