Class: LB::Operation
- Inherits:
-
Object
- Object
- LB::Operation
- Extended by:
- Dry::Configurable
- Includes:
- Log
- Defined in:
- lib/lb/operation.rb,
lib/lb/operation/log.rb,
lib/lb/operation/version.rb
Overview
Base class for operations
Defined Under Namespace
Modules: Log
Constant Summary collapse
- VERSION =
Version
'0.0.1'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.operation_name ⇒ Symbol
Retrieves the operation name.
Instance Method Summary collapse
-
#call ⇒ self
Executes the operation.
-
#handle_exception(error) ⇒ self
Handles exception if given: Logs message and backtrace as :error.
-
#value(*args) ⇒ Object
Executes the operation with given arguments.
Methods included from Log
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/lb/operation.rb', line 19 def config @config end |
Class Method Details
.operation_name ⇒ Symbol
Retrieves the operation name.
24 25 26 |
# File 'lib/lb/operation.rb', line 24 def self.operation_name config.name end |
Instance Method Details
#call ⇒ self
Executes the operation.
31 32 33 |
# File 'lib/lb/operation.rb', line 31 def call raise NotImplementedError, 'Override Operation#call(*args)!' end |
#handle_exception(error) ⇒ self
Handles exception if given: Logs message and backtrace as :error.
49 50 51 52 53 54 55 56 |
# File 'lib/lb/operation.rb', line 49 def handle_exception(error) return self unless error.key?(:exception) exception = error.fetch(:exception) log :error, exception. log :error, exception.backtrace.inspect self end |
#value(*args) ⇒ Object
Executes the operation with given arguments. Returns result or value of result if result responds to :value.
40 41 42 43 |
# File 'lib/lb/operation.rb', line 40 def value(*args) result = call(*args) result.respond_to?(:value) ? result.value : result end |