Class: FService::Result::Failure
- Defined in:
- lib/f_service/result/failure.rb
Overview
Represents a value of a failed operation. The error field can contain any information you want.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the provided error.
Instance Method Summary collapse
-
#failed? ⇒ Boolean
Returns true.
-
#initialize(error) ⇒ Failure
constructor
Creates a failed operation.
-
#successful? ⇒ Boolean
Returns false.
-
#then ⇒ self
Returns itself to the given block.
-
#to_s ⇒ String
Outputs a string representation of the object.
-
#value ⇒ Object
Failed operations do not have value.
-
#value! ⇒ Object
Raises an exception if called.
Methods inherited from Base
Constructor Details
#initialize(error) ⇒ Failure
Creates a failed operation. You usually shouldn’t call this directly. See Base#failure.
20 21 22 23 |
# File 'lib/f_service/result/failure.rb', line 20 def initialize(error) @error = error freeze end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the provided error
14 15 16 |
# File 'lib/f_service/result/failure.rb', line 14 def error @error end |
Instance Method Details
#failed? ⇒ Boolean
Returns true.
43 44 45 |
# File 'lib/f_service/result/failure.rb', line 43 def failed? true end |
#successful? ⇒ Boolean
Returns false.
32 33 34 |
# File 'lib/f_service/result/failure.rb', line 32 def successful? false end |
#then ⇒ self
Returns itself to the given block. Use this to chain multiple service calls (since all services return Results). It will short circuit your service call chain.
79 80 81 |
# File 'lib/f_service/result/failure.rb', line 79 def then self end |
#to_s ⇒ String
Outputs a string representation of the object
91 92 93 |
# File 'lib/f_service/result/failure.rb', line 91 def to_s error.nil? ? 'Failure()' : "Failure(#{error.inspect})" end |
#value ⇒ Object
Failed operations do not have value.
48 49 50 |
# File 'lib/f_service/result/failure.rb', line 48 def value nil end |