Class: Ippon::Validate::Merge

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(left, right) ⇒ Merge

Returns a new instance of Merge.



876
877
878
879
# File 'lib/ippon/validate.rb', line 876

def initialize(left, right)
  @left = left
  @right = right
end

Instance Attribute Details

#leftSchema (readonly)

Returns:



872
873
874
# File 'lib/ippon/validate.rb', line 872

def left
  @left
end

#rightSchema (readonly)

Returns:



874
875
876
# File 'lib/ippon/validate.rb', line 874

def right
  @right
end

Instance Method Details

#process(result) ⇒ Object

Implements the Schema#process interface.



882
883
884
885
886
887
888
889
890
891
892
893
# File 'lib/ippon/validate.rb', line 882

def process(result)
  left_result = @left.validate(result.value)
  right_result = @right.validate(result.value)

  result.mutable_errors.merge!(left_result.errors) if left_result.error?
  result.mutable_errors.merge!(right_result.errors) if right_result.error?

  result.value = {}
  result.value.update(left_result.value) if !left_result.halted?
  result.value.update(right_result.value) if !right_result.halted?
  result
end