Class: Ipregistry::BatchResponse::Result

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#errorApiError? (readonly)

Returns the entry's failure, or nil when it succeeded.

Returns:

  • (ApiError, nil)

    the entry's failure, or nil when it succeeded



32
33
34
# File 'lib/ipregistry/batch_response.rb', line 32

def error
  @error
end

#valueObject? (readonly)

Returns the resolved value, or nil when the entry failed.

Returns:

  • (Object, nil)

    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

Returns:

  • (Boolean)


51
52
53
# File 'lib/ipregistry/batch_response.rb', line 51

def failure?
  !success?
end

#success?Boolean

Returns:

  • (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.

Raises:



56
57
58
59
60
# File 'lib/ipregistry/batch_response.rb', line 56

def value!
  raise @error if @error

  @value
end