Class: Errant::Failure
Constant Summary
Constants inherited from Result
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
readonly
Returns the value of attribute exceptions.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#each_error {|value| ... } ⇒ Object
Perform side effects using the error.
-
#initialize(value, exc = Result::DEFAULT_EXCEPTIONS) ⇒ Failure
constructor
A new instance of Failure.
-
#map_error(&blk) ⇒ Object
Pass the wrapped error into the given block and then rewrap the return value in a new Failure.
- #method_missing(name, *args, &block) ⇒ Object
-
#or_else {|value| ... } ⇒ Object
Pass the wrapped error into the given block, returning an unwrapped value from the block.
- #successful? ⇒ Boolean
- #to_a ⇒ Object
- #to_ary ⇒ Object
Methods inherited from Result
Constructor Details
#initialize(value, exc = Result::DEFAULT_EXCEPTIONS) ⇒ Failure
Returns a new instance of Failure.
5 6 7 8 |
# File 'lib/errant/failure.rb', line 5 def initialize(value, exc = Result::DEFAULT_EXCEPTIONS) @value = value @exceptions = exc end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
10 11 12 |
# File 'lib/errant/failure.rb', line 10 def method_missing(name, *args, &block) self end |
Instance Attribute Details
#exceptions ⇒ Object (readonly)
Returns the value of attribute exceptions.
3 4 5 |
# File 'lib/errant/failure.rb', line 3 def exceptions @exceptions end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/errant/failure.rb', line 3 def value @value end |
Class Method Details
.[](value, exc = Result::DEFAULT_EXCEPTIONS) ⇒ Object
46 47 48 |
# File 'lib/errant/failure.rb', line 46 def self.[](value, exc = Result::DEFAULT_EXCEPTIONS) Failure.new(value, exc) end |
Instance Method Details
#each_error {|value| ... } ⇒ Object
Perform side effects using the error. This is useful for logging and debugging, although it should generally be avoided in production code, in favor of error handling at a single location.
23 24 25 26 |
# File 'lib/errant/failure.rb', line 23 def each_error(&blk) yield value self end |
#map_error(&blk) ⇒ Object
Pass the wrapped error into the given block and then rewrap the return value in a new Failure. This is useful for normalization.
30 31 32 |
# File 'lib/errant/failure.rb', line 30 def map_error(&blk) Failure.new(yield(value)) end |
#or_else {|value| ... } ⇒ Object
Pass the wrapped error into the given block, returning an unwrapped value from the block. This is useful for providing defaults.
16 17 18 |
# File 'lib/errant/failure.rb', line 16 def or_else(&blk) yield value end |
#successful? ⇒ Boolean
34 35 36 |
# File 'lib/errant/failure.rb', line 34 def successful? false end |
#to_a ⇒ Object
38 39 40 |
# File 'lib/errant/failure.rb', line 38 def to_a [] end |
#to_ary ⇒ Object
42 43 44 |
# File 'lib/errant/failure.rb', line 42 def to_ary signal end |