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.



901
902
903
# File 'lib/ippon/validate.rb', line 901

def initialize(element_schema)
  @element_schema = element_schema
end

Instance Attribute Details

#element_schemaSchema (readonly)

Returns:



899
900
901
# File 'lib/ippon/validate.rb', line 899

def element_schema
  @element_schema
end

Instance Method Details

#process(result) ⇒ Object

Implements the Schema#process interface.



906
907
908
909
910
911
912
913
914
915
916
917
# File 'lib/ippon/validate.rb', line 906

def process(result)
  new_value = []

  result.value.each_with_index.map do |element, idx|
    element_result = @element_schema.validate(element)
    new_value << element_result.value
    result.add_nested(idx, element_result)
  end

  result.value = new_value
  result
end