Sha256: 8237d5cf0b6bd1181cb5d16a2d27f65820029650d81f3649694484bbd25e3af1
Contents?: true
Size: 836 Bytes
Versions: 1
Compression:
Stored size: 836 Bytes
Contents
require 'dry/logic/evaluator' module Dry module Logic class Rule::Check < Rule::Value attr_reader :name, :evaluator def self.new(predicate, options) keys = options.fetch(:keys) evaluator = Evaluator::Set.new(keys) super(predicate, options.merge(evaluator: evaluator)) end def initialize(predicate, options) super @name = options.fetch(:name) @evaluator = options[:evaluator] end def call(input) args = evaluator[input].reverse *head, tail = args Logic.Result(predicate.curry(*head).(tail), curry(*args), input) end def evaluate(input) evaluator[input].first end def type :check end def to_ast [type, [name, 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/check.rb |