Class: SorbetOperation::Base Abstract
- Inherits:
-
Object
- Object
- SorbetOperation::Base
- 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:
-
define the ValueType type member
-
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
. type_member { { upper: Object } }
Instance Attribute Summary collapse
-
#logger ⇒ void
writeonly
The logger for this operation.
Instance Method Summary collapse
-
#perform ⇒ Result[ValueType]
Performs the operation and returns the result.
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
#perform ⇒ Result[ValueType]
Performs the operation and returns the result.
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 |