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



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

def error
  @error
end

#exceptionException? (readonly)

Returns An optional exception which caused the failure.

Returns:

  • (Exception, nil)

    An optional exception which caused the failure



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

def exception
  @exception
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.



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

def value
  @value
end

Class Method Details

.fail(error, exception = nil) ⇒ Result

Create a failed result with the provided error description.

Parameters:

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

Returns:



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

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

.success(value) ⇒ Result

Create a successful result with the provided value.

Parameters:

  • value (Object, nil)

Returns:



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

def self.success(value)
  Result.new(value)
end

Instance Method Details

#success?Boolean

Was this result successful or did it encounter an error?

Returns:

  • (Boolean)


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

def success?
  @error.nil?
end