Sha256: 57bf854b93f27e8de248127231dd42d9fa613c3d5b05d5ce718b0758eef09983

Contents?: true

Size: 864 Bytes

Versions: 3

Compression:

Stored size: 864 Bytes

Contents

module Dry
  module Validation
    class Rule::Composite < Rule
      include Dry::Equalizer(:left, :right)

      attr_reader :name, :left, :right

      def initialize(left, right)
        @name = left.name
        @left = left
        @right = right
      end

      def to_ary
        [type, [left.to_ary, right.to_ary]]
      end
      alias_method :to_a, :to_ary
    end

    class Rule::Implication < Rule::Composite
      def call(input)
        left.(input) > right
      end

      def type
        :implication
      end
    end

    class Rule::Conjunction < Rule::Composite
      def call(input)
        left.(input).and(right)
      end

      def type
        :and
      end
    end

    class Rule::Disjunction < Rule::Composite
      def call(input)
        left.(input).or(right)
      end

      def type
        :or
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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