Class: FService::Result::Success
- Defined in:
- lib/f_service/result/success.rb
Overview
Represents a value of a successful operation. The value field can contain any information you want.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the provided value.
Instance Method Summary collapse
-
#error ⇒ nil
Successful operations do not have error.
-
#failed? ⇒ Boolean
Returns false.
-
#initialize(value) ⇒ Success
constructor
Creates a successful operation.
-
#successful? ⇒ Boolean
Returns true.
-
#then {|value| ... } ⇒ Object
Returns its value to the given block.
-
#to_s ⇒ String
Outputs a string representation of the object.
-
#value! ⇒ Object
Returns the provided value.
Methods inherited from Base
Constructor Details
#initialize(value) ⇒ Success
Creates a successful operation. You usually shouldn’t call this directly. See Base#success.
19 20 21 22 |
# File 'lib/f_service/result/success.rb', line 19 def initialize(value) @value = value freeze end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the provided value.
13 14 15 |
# File 'lib/f_service/result/success.rb', line 13 def value @value end |
Instance Method Details
#error ⇒ nil
Successful operations do not have error.
54 55 56 |
# File 'lib/f_service/result/success.rb', line 54 def error nil end |
#failed? ⇒ Boolean
Returns false.
42 43 44 |
# File 'lib/f_service/result/success.rb', line 42 def failed? false end |
#successful? ⇒ Boolean
Returns true.
31 32 33 |
# File 'lib/f_service/result/success.rb', line 31 def successful? true end |
#then {|value| ... } ⇒ Object
Returns its value to the given block. Use this to chain multiple service calls (since all services return Results).
78 79 80 |
# File 'lib/f_service/result/success.rb', line 78 def then yield value end |
#to_s ⇒ String
Outputs a string representation of the object
90 91 92 |
# File 'lib/f_service/result/success.rb', line 90 def to_s value.nil? ? 'Success()' : "Success(#{value.inspect})" end |
#value! ⇒ Object
Returns the provided value.
47 48 49 |
# File 'lib/f_service/result/success.rb', line 47 def value! value end |