Class: Dry::Validation::Rule::Result
- Inherits:
-
Object
- Object
- Dry::Validation::Rule::Result
show all
- Defined in:
- lib/dry/validation/rule/result.rb
Defined Under Namespace
Classes: Set, Value, Verified
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(input, value, rule) ⇒ Result
Returns a new instance of Result.
59
60
61
62
63
64
|
# File 'lib/dry/validation/rule/result.rb', line 59
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/validation/rule/result.rb', line 14
def input
@input
end
|
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/dry/validation/rule/result.rb', line 14
def name
@name
end
|
#rule ⇒ Object
Returns the value of attribute rule.
14
15
16
|
# File 'lib/dry/validation/rule/result.rb', line 14
def rule
@rule
end
|
#value ⇒ Object
Returns the value of attribute value.
14
15
16
|
# File 'lib/dry/validation/rule/result.rb', line 14
def value
@value
end
|
Instance Method Details
#>(other) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/dry/validation/rule/result.rb', line 82
def >(other)
if success?
other.(input)
else
Validation.Result(input, true, rule)
end
end
|
#and(other) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/dry/validation/rule/result.rb', line 90
def and(other)
if success?
other.(input)
else
self
end
end
|
#call ⇒ Object
66
67
68
|
# File 'lib/dry/validation/rule/result.rb', line 66
def call
self
end
|
#curry(predicate_id = nil) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/dry/validation/rule/result.rb', line 70
def curry(predicate_id = nil)
if predicate_id
Rule::Result::Verified.new(self, predicate_id)
else
self
end
end
|
#failure? ⇒ Boolean
114
115
116
|
# File 'lib/dry/validation/rule/result.rb', line 114
def failure?
! success?
end
|
#negated ⇒ Object
78
79
80
|
# File 'lib/dry/validation/rule/result.rb', line 78
def negated
self.class.new(input, !value, rule)
end
|
#or(other) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/dry/validation/rule/result.rb', line 98
def or(other)
if success?
self
else
other.(input)
end
end
|
#success? ⇒ Boolean
110
111
112
|
# File 'lib/dry/validation/rule/result.rb', line 110
def success?
@value
end
|
#xor(other) ⇒ Object
106
107
108
|
# File 'lib/dry/validation/rule/result.rb', line 106
def xor(other)
Validation.Result(input, success? ^ other.(input).success?, rule)
end
|