Class: Dry::Logic::Operations::And
Instance Attribute Summary collapse
Attributes inherited from Binary
#left, #right
Attributes inherited from Abstract
#options, #rules
Instance Method Summary
collapse
Methods inherited from Binary
#ast, #to_s
Methods inherited from Abstract
#curry, #id, #new, #to_ast, #with
#and, #or, #then, #xor
Constructor Details
#initialize ⇒ And
9
10
11
12
|
# File 'lib/dry/logic/operations/and.rb', line 9
def initialize(*, **)
super
@hints = options.fetch(:hints, true)
end
|
Instance Attribute Details
#hints ⇒ Object
Returns the value of attribute hints.
7
8
9
|
# File 'lib/dry/logic/operations/and.rb', line 7
def hints
@hints
end
|
Instance Method Details
#[](input) ⇒ Object
38
39
40
|
# File 'lib/dry/logic/operations/and.rb', line 38
def [](input)
left[input] && right[input]
end
|
#call(input) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dry/logic/operations/and.rb', line 19
def call(input)
left_result = left.(input)
if left_result.success?
right_result = right.(input)
if right_result.success?
Result::SUCCESS
else
Result.new(false, id) { right_result.ast(input) }
end
else
Result.new(false, id) do
left_ast = left_result.to_ast
hints ? [type, [left_ast, [:hint, right.ast(input)]]] : left_ast
end
end
end
|
#type ⇒ Object
Also known as:
operator
14
15
16
|
# File 'lib/dry/logic/operations/and.rb', line 14
def type
:and
end
|