Class: SorbetOperation::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Helpers, T::Sig
Defined in:
lib/sorbet_operation/base.rb

Overview

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

Abstract base class for operations.

Subclasses must:

  1. define the ValueType type member

  2. implement the #execute method

Constant Summary collapse

ValueType =

The type of the value returned by this operation. The type can be any valid Sorbet type, as long as it’s a subtype of Object.

Examples:

If the operation returns a String or nil

ValueType = type_member { { fixed: T.nilable(String) } }

If the operation does not return a value

ValueType = type_member { { fixed: NilClass } }

See Also:

type_member { { upper: Object } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#logger=(value) ⇒ void

This method returns an undefined value.

The logger for this operation.



58
59
60
# File 'lib/sorbet_operation/base.rb', line 58

def logger=(value)
  @logger = value
end

Instance Method Details

#performResult[ValueType]

Performs the operation and returns the result.

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sorbet_operation/base.rb', line 40

def perform
  logger.debug("Performing operation #{self.class.name}")

  begin
    value = execute
  rescue Failure => e
    logger.debug("Operation #{self.class.name} failed, failure = #{e.inspect}")

    Result.new(false, nil, e)
  else
    logger.debug("Operation #{self.class.name} succeeded, return value = #{value.inspect}")

    Result.new(true, value, nil)
  end
end