Sha256: b32aa582affcebd3894a3422a1f71b6af7f94302b54550fa8fd6b7786fe3ae98

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

module Dry
  module Validation
    class Rule
      include Dry::Equalizer(:name, :predicate)

      attr_reader :name, :predicate

      def initialize(name, predicate)
        @name = name
        @predicate = predicate
      end

      def to_ary
        [type, [name, predicate.to_ary]]
      end
      alias_method :to_a, :to_ary

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

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

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

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

require 'dry/validation/rule/key'
require 'dry/validation/rule/value'
require 'dry/validation/rule/each'
require 'dry/validation/rule/set'
require 'dry/validation/rule/composite'
require 'dry/validation/rule/group'
require 'dry/validation/rule/result'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-validation-0.3.1 lib/dry/validation/rule.rb
dry-validation-0.3.0 lib/dry/validation/rule.rb