Sha256: fcca407aa375247d984535e89d1a5c7c91efec9b0e7143a317e67ed4e9d758b4

Contents?: true

Size: 748 Bytes

Versions: 5

Compression:

Stored size: 748 Bytes

Contents

# frozen_string_literal: true

require 'dry/logic/operations/binary'
require 'dry/logic/result'

module Dry
  module Logic
    module Operations
      class Or < Binary
        def type
          :or
        end
        alias_method :operator, :type

        def call(input)
          left_result = left.(input)

          if left_result.success?
            Result::SUCCESS
          else
            right_result = right.(input)

            if right_result.success?
              Result::SUCCESS
            else
              Result.new(false, id) { [:or, [left_result.to_ast, right_result.to_ast]] }
            end
          end
        end

        def [](input)
          left[input] || right[input]
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-logic-1.0.6 lib/dry/logic/operations/or.rb
dry-logic-1.0.5 lib/dry/logic/operations/or.rb
dry-logic-1.0.4 lib/dry/logic/operations/or.rb
dry-logic-1.0.3 lib/dry/logic/operations/or.rb
dry-logic-1.0.2 lib/dry/logic/operations/or.rb