Class: Dry::Logic::Rule::Check
- Inherits:
-
Value
- Object
- Dry::Logic::Rule
- Value
- Dry::Logic::Rule::Check
- Defined in:
- lib/dry/logic/rule/check.rb
Instance Attribute Summary collapse
-
#evaluator ⇒ Object
readonly
Returns the value of attribute evaluator.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Dry::Logic::Rule
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object
- #evaluate(input) ⇒ Object
-
#initialize(predicate, options) ⇒ Check
constructor
A new instance of Check.
- #to_ast ⇒ Object
- #type ⇒ Object
Methods inherited from Value
Methods inherited from Dry::Logic::Rule
#and, #curry, #each?, #negation, #new, #or, #predicate_id, #then, #xor
Constructor Details
#initialize(predicate, options) ⇒ Check
Returns a new instance of Check.
15 16 17 18 19 |
# File 'lib/dry/logic/rule/check.rb', line 15 def initialize(predicate, ) super @name = .fetch(:name) @evaluator = [:evaluator] end |
Instance Attribute Details
#evaluator ⇒ Object (readonly)
Returns the value of attribute evaluator.
6 7 8 |
# File 'lib/dry/logic/rule/check.rb', line 6 def evaluator @evaluator end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/dry/logic/rule/check.rb', line 6 def name @name end |
Class Method Details
Instance Method Details
#call(input) ⇒ Object
21 22 23 24 25 |
# File 'lib/dry/logic/rule/check.rb', line 21 def call(input) args = evaluator[input].reverse *head, tail = args Logic.Result(predicate.curry(*head).(tail), head.size > 0 ? curry(*head) : self, input) end |
#evaluate(input) ⇒ Object
27 28 29 |
# File 'lib/dry/logic/rule/check.rb', line 27 def evaluate(input) evaluator[input].first end |
#to_ast ⇒ Object
35 36 37 |
# File 'lib/dry/logic/rule/check.rb', line 35 def to_ast [type, [name, predicate.to_ast]] end |
#type ⇒ Object
31 32 33 |
# File 'lib/dry/logic/rule/check.rb', line 31 def type :check end |