Class: Dry::Logic::Operations::Check
- Inherits:
-
Unary
show all
- Defined in:
- lib/dry/logic/operations/check.rb
Instance Attribute Summary collapse
Attributes inherited from Unary
#rule
Attributes inherited from Abstract
#options, #rules
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Unary
#to_s
Methods inherited from Abstract
#curry, #id, #new, #to_ast, #with
#and, #or, #then, #xor
Constructor Details
#initialize(*rules, **options) ⇒ Check
Returns a new instance of Check.
24
25
26
27
|
# File 'lib/dry/logic/operations/check.rb', line 24
def initialize(*rules, **options)
super
@evaluator = options[:evaluator]
end
|
Instance Attribute Details
#evaluator ⇒ Object
Returns the value of attribute evaluator.
11
12
13
|
# File 'lib/dry/logic/operations/check.rb', line 11
def evaluator
@evaluator
end
|
Class Method Details
.new(rule, **options) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/dry/logic/operations/check.rb', line 13
def self.new(rule, **options)
if options[:evaluator]
super(rule, options)
else
keys = options.fetch(:keys)
evaluator = Evaluator::Set.new(keys)
super(rule, options.merge(evaluator: evaluator))
end
end
|
Instance Method Details
#[](input) ⇒ Object
44
45
46
|
# File 'lib/dry/logic/operations/check.rb', line 44
def [](input)
rule[*evaluator[input].reverse]
end
|
#ast(input = Undefined) ⇒ Object
48
49
50
|
# File 'lib/dry/logic/operations/check.rb', line 48
def ast(input = Undefined)
[type, [options[:keys], rule.ast(input)]]
end
|
#call(input) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/dry/logic/operations/check.rb', line 33
def call(input)
*head, tail = evaluator[input]
result = rule.curry(*head).(tail)
if result.success?
Result::SUCCESS
else
Result.new(false, id) { [type, [options[:keys], result.to_ast]] }
end
end
|
#type ⇒ Object
29
30
31
|
# File 'lib/dry/logic/operations/check.rb', line 29
def type
:check
end
|