Sha256: 5141b9a175539c961e7388d4fdf90c33ace36c84723a0266814141c76123496d

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

module Dry
  module Logic
    class Rule::Value < Rule
      def type
        :val
      end

      def nulary?
        arity == 0
      end

      def arity
        @arity ||= predicate.arity
      end

      def args
        @args ||= predicate.args
      end

      def input
        predicate.args.last
      end

      def call(input)
        if nulary?
          Logic.Result(predicate.(), self, input)
        else
          evaled = evaluate(input)
          result = apply(evaled)
          rule = result == true ? self : curry(evaled)
          Logic.Result(result, rule, input)
        end
      end

      def apply(input)
        predicate.(input)
      end

      def evaluate(input)
        input
      end

      def to_ast
        [type, predicate.to_ast]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-logic-0.3.0 lib/dry/logic/rule/value.rb