Class: Ippon::Validate::ForEach

Inherits:
Schema
  • Object
show all
Defined in:
lib/ippon/validate.rb

Overview

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Schema

#&, #unhalt, #validate, #validate!, #|

Constructor Details

#initialize(element_schema) ⇒ ForEach

Returns a new instance of ForEach.


802
803
804
# File 'lib/ippon/validate.rb', line 802

def initialize(element_schema)
  @element_schema = element_schema
end

Instance Attribute Details

#element_schemaSchema (readonly)

Returns:


800
801
802
# File 'lib/ippon/validate.rb', line 800

def element_schema
  @element_schema
end

Instance Method Details

#process(result) ⇒ Object

Implements the Schema#process interface.


807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
# File 'lib/ippon/validate.rb', line 807

def process(result)
  results = result.value.each_with_index.map do |element, idx|
    element_result = result.dup.push_path(idx)
    element_result.value = element
    @element_schema.process(element_result)
    element_result
  end

  results.each do |element_result|
    if element_result.halted?
      result.halt
    end

    result.add_errors_from(element_result)
  end

  result.value = results.map(&:value)
end