Class: Plumb::Result
- Inherits:
-
Object
- Object
- Plumb::Result
- Defined in:
- lib/plumb/result.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value, errors: nil) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
- #invalid(val = value, errors: nil) ⇒ Object
- #invalid? ⇒ Boolean
- #reset(val) ⇒ Object
- #valid(val = value) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(value, errors: nil) ⇒ Result
Returns a new instance of Result.
23 24 25 26 |
# File 'lib/plumb/result.rb', line 23 def initialize(value, errors: nil) @value = value @errors = errors end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
21 22 23 |
# File 'lib/plumb/result.rb', line 21 def errors @errors end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
21 22 23 |
# File 'lib/plumb/result.rb', line 21 def value @value end |
Class Method Details
.invalid(value = nil, errors: nil) ⇒ Object
10 11 12 |
# File 'lib/plumb/result.rb', line 10 def invalid(value = nil, errors: nil) Invalid.new(value, errors:) end |
.valid(value) ⇒ Object
6 7 8 |
# File 'lib/plumb/result.rb', line 6 def valid(value) Valid.new(value) end |
.wrap(value) ⇒ Object
14 15 16 17 18 |
# File 'lib/plumb/result.rb', line 14 def wrap(value) return value if value.is_a?(Result) valid(value) end |
Instance Method Details
#inspect ⇒ Object
31 32 33 |
# File 'lib/plumb/result.rb', line 31 def inspect %(<#{self.class}##{object_id} value:#{value.inspect} errors:#{errors.inspect}>) end |
#invalid(val = value, errors: nil) ⇒ Object
45 46 47 |
# File 'lib/plumb/result.rb', line 45 def invalid(val = value, errors: nil) Result.invalid(val, errors:) end |
#invalid? ⇒ Boolean
29 |
# File 'lib/plumb/result.rb', line 29 def invalid? = false |
#reset(val) ⇒ Object
35 36 37 38 39 |
# File 'lib/plumb/result.rb', line 35 def reset(val) @value = val @errors = nil self end |
#valid(val = value) ⇒ Object
41 42 43 |
# File 'lib/plumb/result.rb', line 41 def valid(val = value) Result.valid(val) end |
#valid? ⇒ Boolean
28 |
# File 'lib/plumb/result.rb', line 28 def valid? = true |