Sha256: 03ee0883bebac97464f340c15247e148fe087616a60c0830d655fa94fdf25176

Contents?: true

Size: 748 Bytes

Versions: 6

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

6 entries across 6 versions & 2 rubygems

Version Path
dry-logic-1.2.0 lib/dry/logic/operations/or.rb
dry-logic-1.1.1 lib/dry/logic/operations/or.rb
dry-logic-1.1.0 lib/dry/logic/operations/or.rb
dry-logic-1.0.8 lib/dry/logic/operations/or.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/dry-logic-1.0.7/lib/dry/logic/operations/or.rb
dry-logic-1.0.7 lib/dry/logic/operations/or.rb