Sha256: 369f2fb6162dc5967fdc1c351263a4d19b02cf935c25c28aae2a5b45085d23f8

Contents?: true

Size: 850 Bytes

Versions: 15

Compression:

Stored size: 850 Bytes

Contents

module Datacaster
  class AndWithErrorAggregationNode < Base
    def initialize(left, right)
      @left = left
      @right = right
    end

    # Works like AndNode, but doesn't stop at first error — in order to aggregate all Failures
    # Makes sense only for Hash Schemas
    def cast(object, runtime:)
      left_result = @left.with_runtime(runtime).(object)

      if left_result.valid?
        @right.with_runtime(runtime).(left_result.value)
      else
        right_result = @right.with_runtime(runtime).(object)
        if right_result.valid?
          left_result
        else
          Datacaster.ErrorResult(Utils.merge_errors(left_result.raw_errors, right_result.raw_errors))
        end
      end
    end

    def inspect
      "#<Datacaster::AndWithErrorAggregationNode L: #{@left.inspect} R: #{@right.inspect}>"
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
datacaster-4.1.0 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-4.0.1 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.3.1 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.3.0 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.7 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.6 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.5 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.4 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.3 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.2 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.1 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.2.0 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.1.5 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.1.3 lib/datacaster/and_with_error_aggregation_node.rb
datacaster-3.1.2 lib/datacaster/and_with_error_aggregation_node.rb