Class: Dry::Logic::Result
- Inherits:
-
Object
- Object
- Dry::Logic::Result
show all
- Defined in:
- lib/dry/logic/result.rb
Defined Under Namespace
Classes: LazyValue, Set, Value, Verified, Wrapped
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(input, value, rule) ⇒ Result
Returns a new instance of Result.
77
78
79
80
81
82
|
# File 'lib/dry/logic/result.rb', line 77
def initialize(input, value, rule)
@input = input
@value = value
@rule = rule
@name = rule.name
end
|
Instance Attribute Details
Returns the value of attribute input.
14
15
16
|
# File 'lib/dry/logic/result.rb', line 14
def input
@input
end
|
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/dry/logic/result.rb', line 14
def name
@name
end
|
#rule ⇒ Object
Returns the value of attribute rule.
14
15
16
|
# File 'lib/dry/logic/result.rb', line 14
def rule
@rule
end
|
#value ⇒ Object
Returns the value of attribute value.
14
15
16
|
# File 'lib/dry/logic/result.rb', line 14
def value
@value
end
|
Instance Method Details
#>(other) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/dry/logic/result.rb', line 100
def >(other)
if success?
other.(input)
else
Logic.Result(input, true, rule)
end
end
|
#and(other) ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/dry/logic/result.rb', line 108
def and(other)
if success?
other.(input)
else
self
end
end
|
#call ⇒ Object
84
85
86
|
# File 'lib/dry/logic/result.rb', line 84
def call(*)
self
end
|
#curry(predicate_id = nil) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/dry/logic/result.rb', line 88
def curry(predicate_id = nil)
if predicate_id
Result::Verified.new(self, predicate_id)
else
self
end
end
|
#failure? ⇒ Boolean
132
133
134
|
# File 'lib/dry/logic/result.rb', line 132
def failure?
! success?
end
|
#negated ⇒ Object
96
97
98
|
# File 'lib/dry/logic/result.rb', line 96
def negated
self.class.new(input, !value, rule)
end
|
#or(other) ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/dry/logic/result.rb', line 116
def or(other)
if success?
self
else
other.(input)
end
end
|
#success? ⇒ Boolean
128
129
130
|
# File 'lib/dry/logic/result.rb', line 128
def success?
@value
end
|
#xor(other) ⇒ Object
124
125
126
|
# File 'lib/dry/logic/result.rb', line 124
def xor(other)
Logic.Result(input, success? ^ other.(input).success?, rule)
end
|