Class: ClearLogic::StepAdapters::Stride
- Inherits:
-
Object
- Object
- ClearLogic::StepAdapters::Stride
- Includes:
- Result, Dry::Monads::Result::Mixin
- Defined in:
- lib/clear_logic/step_adapters/stride.rb
Constant Summary
Constants included from Result
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(operation, options, args) ⇒ Object
- #catch_error(error) ⇒ Object
- #failure_method ⇒ Object
- #log_result ⇒ Object
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 11 def args @args end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 11 def context @context end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
11 12 13 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 11 def operation @operation end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 11 def @options end |
Instance Method Details
#call(operation, options, args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 13 def call(operation, , args) @operation = operation @options = @args = args @context = args.flatten.first [:rescue] ||= {} context.step = [:step_name] return success(context) if context.exit_success? result = operation.call(context) log_result return result if result.success? failure_method rescue *Array([:rescue].keys) => e catch_error(e) end |
#catch_error(error) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 36 def catch_error(error) context.catched_error = error log_result rescue_method = [:rescue][error.class] rescue_method ? context.service.send(rescue_method, context) : failure(context) end |
#failure_method ⇒ Object
51 52 53 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 51 def failure_method [:failure] ? context.service.send([:failure], context) : failure(context) end |
#log_result ⇒ Object
45 46 47 48 49 |
# File 'lib/clear_logic/step_adapters/stride.rb', line 45 def log_result return unless [:log] || context.service.class.[:log_all] context.service.class.logger_instance.info(context) end |