Class: Cuprum::Result
- Inherits:
-
Object
- Object
- Cuprum::Result
- Defined in:
- lib/cuprum/result.rb
Overview
Data object that encapsulates the result of calling a Cuprum command.
Constant Summary collapse
- STATUSES =
%i[success failure].freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
The error (if any) generated when the command was called.
-
#status ⇒ Symbol
readonly
The status of the result, either :success or :failure.
-
#value ⇒ Object
readonly
The value returned by calling the command.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the other object to the result.
-
#failure? ⇒ Boolean
True if the result status is :failure, otherwise false.
-
#initialize(value: nil, error: nil, status: nil) ⇒ Result
constructor
A new instance of Result.
-
#success? ⇒ Boolean
True if the result status is :success, otherwise false.
-
#to_cuprum_result ⇒ Cuprum::Result
The result.
Constructor Details
#initialize(value: nil, error: nil, status: nil) ⇒ Result
Returns a new instance of Result.
15 16 17 18 19 |
# File 'lib/cuprum/result.rb', line 15 def initialize(value: nil, error: nil, status: nil) @value = value @error = error @status = resolve_status(status) end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the error (if any) generated when the command was called.
26 27 28 |
# File 'lib/cuprum/result.rb', line 26 def error @error end |
#status ⇒ Symbol (readonly)
Returns the status of the result, either :success or :failure.
29 30 31 |
# File 'lib/cuprum/result.rb', line 29 def status @status end |
#value ⇒ Object (readonly)
Returns the value returned by calling the command.
22 23 24 |
# File 'lib/cuprum/result.rb', line 22 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Compares the other object to the result.
41 42 43 44 45 46 47 |
# File 'lib/cuprum/result.rb', line 41 def ==(other) return false unless other.respond_to?(:value) && other.value == value return false unless other.respond_to?(:status) && other.status == status return false unless other.respond_to?(:error) && other.error == error true end |
#failure? ⇒ Boolean
Returns true if the result status is :failure, otherwise false.
51 52 53 |
# File 'lib/cuprum/result.rb', line 51 def failure? @status == :failure end |
#success? ⇒ Boolean
Returns true if the result status is :success, otherwise false.
56 57 58 |
# File 'lib/cuprum/result.rb', line 56 def success? @status == :success end |
#to_cuprum_result ⇒ Cuprum::Result
Returns The result.
61 62 63 |
# File 'lib/cuprum/result.rb', line 61 def to_cuprum_result self end |