Class: LaunchDarkly::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/util.rb

Overview

A Result is used to reflect the outcome of any operation.

Results can either be considered a success or a failure.

In the event of success, the Result will contain an option, nullable value to hold any success value back to the calling function.

If the operation fails, the Result will contain an error describing the value.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorString? (readonly)

Returns An error description of the failure; nil otherwise.

Returns:

  • (String, nil)

    An error description of the failure; nil otherwise



55
56
57
# File 'lib/ldclient-rb/util.rb', line 55

def error
  @error
end

#exceptionException? (readonly)

Returns An optional exception which caused the failure.

Returns:

  • (Exception, nil)

    An optional exception which caused the failure



60
61
62
# File 'lib/ldclient-rb/util.rb', line 60

def exception
  @exception
end

#headersHash (readonly)

Returns Optional headers associated with the result.

Returns:

  • (Hash)

    Optional headers associated with the result



65
66
67
# File 'lib/ldclient-rb/util.rb', line 65

def headers
  @headers
end

#valueObject? (readonly)

Returns The value returned from the operation if it was successful; nil otherwise.

Returns:

  • (Object, nil)

    The value returned from the operation if it was successful; nil otherwise.



50
51
52
# File 'lib/ldclient-rb/util.rb', line 50

def value
  @value
end

Class Method Details

.fail(error, exception = nil, headers = nil) ⇒ Result

Create a failed result with the provided error description.

Parameters:

  • error (String)
  • exception (Exception, nil) (defaults to: nil)
  • headers (Hash, nil) (defaults to: nil)

Returns:



34
35
36
# File 'lib/ldclient-rb/util.rb', line 34

def self.fail(error, exception = nil, headers = nil)
  Result.new(nil, error, exception, headers)
end

.success(value, headers = nil) ⇒ Result

Create a successful result with the provided value.

Parameters:

  • value (Object, nil)
  • headers (Hash, nil) (defaults to: nil)

    Optional headers associated with the result

Returns:



22
23
24
# File 'lib/ldclient-rb/util.rb', line 22

def self.success(value, headers = nil)
  Result.new(value, nil, nil, headers)
end

Instance Method Details

#success?Boolean

Was this result successful or did it encounter an error?

Returns:

  • (Boolean)


43
44
45
# File 'lib/ldclient-rb/util.rb', line 43

def success?
  @error.nil?
end