Class: NxtSchema::Node::Collection

Inherits:
Base
  • Object
show all
Defined in:
lib/nxt_schema/node/collection.rb

Instance Attribute Summary

Attributes inherited from Base

#coerced, #coerced_nodes, #context, #error_key, #errors, #index, #input, #locale, #node, #output, #parent, #root

Instance Method Summary collapse

Methods inherited from Base

#add_error, #add_schema_error, #initialize, #merge_errors, #root?, #run_validations, #up, #valid?

Constructor Details

This class inherits a constructor from NxtSchema::Node::Base

Instance Method Details

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nxt_schema/node/collection.rb', line 4

def call
  apply_on_evaluators
  child_nodes # build nodes here so we can access them even when invalid
  return self if maybe_evaluator_applies?

  coerce_input
  validate_filled
  return self unless valid?

  child_nodes.each_with_index do |item, index|
    child_node = item.call

    if !child_node.valid?
      merge_errors(child_node)
    else
      output[index] = child_node.output
    end
  end

  register_as_coerced_when_no_errors
  run_validations

  self
end