Class: Orc::Result

Inherits:
Object
  • Object
show all
Includes:
AbstractType
Defined in:
lib/orc.rb

Overview

Abstract base class for a result returned from some computation

Direct Known Subclasses

Failure, Success

Defined Under Namespace

Classes: Failure, Success

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.failure(object, status = :failure) ⇒ Success

Create a result indicating failure

Parameters:

  • object (Object)

    context information associated with the failure

  • status (Object) (defaults to: :failure)

    an optional, arbitrary status description (symbol)

Returns:



31
32
33
# File 'lib/orc.rb', line 31

def self.failure(object, status = :failure)
  Failure.new(object, status)
end

.success(object, status = :success) ⇒ Success

Create a result indicating success

Parameters:

  • object (Object)

    arbitrary data associated with the result

Returns:



18
19
20
# File 'lib/orc.rb', line 18

def self.success(object, status = :success)
  Success.new(object, status)
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/orc.rb', line 43

def failure?
  !success?
end

#updateObject



47
48
49
# File 'lib/orc.rb', line 47

def update
  self.class.new(yield(object), status)
end