Class: TypedOperation::Result::Failure
- Inherits:
-
Object
- Object
- TypedOperation::Result::Failure
- Defined in:
- lib/typed_operation/result/failure.rb
Overview
Represents a failed result. Immutable value object.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
: (untyped) -> bool.
-
#deconstruct ⇒ Object
Pattern matching support - array destructuring.
-
#deconstruct_keys(keys) ⇒ Object
Pattern matching support - hash destructuring.
-
#failure ⇒ Object
Returns the wrapped error.
-
#failure? ⇒ Boolean
: () -> true.
-
#hash ⇒ Object
: () -> Integer.
-
#initialize(error) ⇒ Failure
constructor
: (untyped) -> void.
-
#inspect ⇒ Object
(also: #to_s)
: () -> String.
-
#success? ⇒ Boolean
: () -> false.
-
#value! ⇒ Object
Raises UnwrapError since this is a Failure.
Constructor Details
#initialize(error) ⇒ Failure
: (untyped) -> void
16 17 18 19 |
# File 'lib/typed_operation/result/failure.rb', line 16 def initialize(error) @error = error freeze end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
13 14 15 |
# File 'lib/typed_operation/result/failure.rb', line 13 def error @error end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
: (untyped) -> bool
61 62 63 |
# File 'lib/typed_operation/result/failure.rb', line 61 def ==(other) other.is_a?(Failure) && other.error == @error end |
#deconstruct ⇒ Object
Pattern matching support - array destructuring. : () -> Array
45 46 47 |
# File 'lib/typed_operation/result/failure.rb', line 45 def deconstruct @error.is_a?(::Array) ? @error : [@error] end |
#deconstruct_keys(keys) ⇒ Object
Pattern matching support - hash destructuring. Delegates to the inner error if it responds to deconstruct_keys. : (Array?) -> Hash[Symbol, untyped]
52 53 54 55 56 57 58 |
# File 'lib/typed_operation/result/failure.rb', line 52 def deconstruct_keys(keys) if @error.respond_to?(:deconstruct_keys) @error.deconstruct_keys(keys) else {error: @error, failure: @error} end end |
#failure ⇒ Object
Returns the wrapped error. : () -> untyped
39 40 41 |
# File 'lib/typed_operation/result/failure.rb', line 39 def failure @error end |
#failure? ⇒ Boolean
: () -> true
27 28 29 |
# File 'lib/typed_operation/result/failure.rb', line 27 def failure? true end |
#hash ⇒ Object
: () -> Integer
67 68 69 |
# File 'lib/typed_operation/result/failure.rb', line 67 def hash [self.class, @error].hash end |
#inspect ⇒ Object Also known as: to_s
: () -> String
72 73 74 |
# File 'lib/typed_operation/result/failure.rb', line 72 def inspect "Failure(#{@error.inspect})" end |
#success? ⇒ Boolean
: () -> false
22 23 24 |
# File 'lib/typed_operation/result/failure.rb', line 22 def success? false end |
#value! ⇒ Object
Raises UnwrapError since this is a Failure. : () -> bot
33 34 35 |
# File 'lib/typed_operation/result/failure.rb', line 33 def value! raise UnwrapError, "Cannot unwrap Failure: #{@error.inspect}" end |