Class: Ipregistry::BatchResponse::Result
- Inherits:
-
Object
- Object
- Ipregistry::BatchResponse::Result
- Defined in:
- lib/ipregistry/batch_response.rb
Overview
One entry of a batch operation: either a value (an Models::IpInfo or Models::UserAgent) or the ApiError explaining why this particular entry failed.
Instance Attribute Summary collapse
-
#error ⇒ ApiError?
readonly
The entry's failure, or nil when it succeeded.
-
#value ⇒ Object?
readonly
The resolved value, or nil when the entry failed.
Class Method Summary collapse
Instance Method Summary collapse
- #deconstruct_keys(_keys) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(value: nil, error: nil) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
-
#value! ⇒ Object
The resolved value, raising the entry's error when it failed.
Constructor Details
#initialize(value: nil, error: nil) ⇒ Result
Returns a new instance of Result.
42 43 44 45 |
# File 'lib/ipregistry/batch_response.rb', line 42 def initialize(value: nil, error: nil) @value = value @error = error end |
Instance Attribute Details
#error ⇒ ApiError? (readonly)
Returns the entry's failure, or nil when it succeeded.
32 33 34 |
# File 'lib/ipregistry/batch_response.rb', line 32 def error @error end |
#value ⇒ Object? (readonly)
Returns the resolved value, or nil when the entry failed.
29 30 31 |
# File 'lib/ipregistry/batch_response.rb', line 29 def value @value end |
Class Method Details
.failure(error) ⇒ Object
38 39 40 |
# File 'lib/ipregistry/batch_response.rb', line 38 def self.failure(error) new(error: error) end |
.success(value) ⇒ Object
34 35 36 |
# File 'lib/ipregistry/batch_response.rb', line 34 def self.success(value) new(value: value) end |
Instance Method Details
#deconstruct_keys(_keys) ⇒ Object
62 63 64 |
# File 'lib/ipregistry/batch_response.rb', line 62 def deconstruct_keys(_keys) { value: @value, error: @error } end |
#failure? ⇒ Boolean
51 52 53 |
# File 'lib/ipregistry/batch_response.rb', line 51 def failure? !success? end |
#success? ⇒ Boolean
47 48 49 |
# File 'lib/ipregistry/batch_response.rb', line 47 def success? @error.nil? end |
#value! ⇒ Object
The resolved value, raising the entry's error when it failed.
56 57 58 59 60 |
# File 'lib/ipregistry/batch_response.rb', line 56 def value! raise @error if @error @value end |