lib/dry/logic/rule/check.rb in dry-logic-0.1.2 vs lib/dry/logic/rule/check.rb in dry-logic-0.1.3
- old
+ new
@@ -1,11 +1,28 @@
module Dry
module Logic
class Rule::Check < Rule
- alias_method :result, :predicate
+ attr_reader :keys
- def call(*args)
- Logic.Result(nil, result.(*args), self)
+ class Unary < Rule::Check
+ def evaluate_input(*)
+ predicate.input
+ end
+ end
+
+ class Binary < Rule::Check
+ def evaluate_input(result)
+ keys.map { |key| result[key].input }
+ end
+ end
+
+ def initialize(name, predicate, keys)
+ super(name, predicate)
+ @keys = keys
+ end
+
+ def call(result)
+ Logic.Result(evaluate_input(result), predicate.(result), self)
end
def type
:check
end