Sha256: 9dcb5a0a0d88dc42ffefb6950b1b8f917b5686807544de8e4685abf6d52b1204

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

module Dry
  module Logic
    class Rule
      include Dry::Equalizer(:predicate, :options)

      attr_reader :predicate

      attr_reader :options

      def initialize(predicate, options = {})
        @predicate = predicate
        @options = options
      end

      def predicate_id
        predicate.id
      end

      def type
        raise NotImplementedError
      end

      def and(other)
        Conjunction.new(self, other)
      end
      alias_method :&, :and

      def or(other)
        Disjunction.new(self, other)
      end
      alias_method :|, :or

      def xor(other)
        ExclusiveDisjunction.new(self, other)
      end
      alias_method :^, :xor

      def then(other)
        Implication.new(self, other)
      end
      alias_method :>, :then

      def negation
        Negation.new(self)
      end

      def new(predicate)
        self.class.new(predicate, options)
      end

      def curry(*args)
        self.class.new(predicate.curry(*args), options)
      end

      def each?
        predicate.is_a?(Rule::Each)
      end
    end
  end
end

require 'dry/logic/rule/value'
require 'dry/logic/rule/key'
require 'dry/logic/rule/attr'
require 'dry/logic/rule/each'
require 'dry/logic/rule/set'
require 'dry/logic/rule/composite'
require 'dry/logic/rule/negation'
require 'dry/logic/rule/check'

require 'dry/logic/result'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-logic-0.2.3 lib/dry/logic/rule.rb
dry-logic-0.2.2 lib/dry/logic/rule.rb
dry-logic-0.2.1 lib/dry/logic/rule.rb
dry-logic-0.2.0 lib/dry/logic/rule.rb