Class: ClearLogic::StepAdapters::Stride

Inherits:
Object
  • Object
show all
Includes:
Result, Dry::Monads::Result::Mixin
Defined in:
lib/clear_logic/step_adapters/stride.rb

Constant Summary

Constants included from Result

Result::DEFAULT_ERRORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



11
12
13
# File 'lib/clear_logic/step_adapters/stride.rb', line 11

def args
  @args
end

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/clear_logic/step_adapters/stride.rb', line 11

def context
  @context
end

#operationObject (readonly)

Returns the value of attribute operation.



11
12
13
# File 'lib/clear_logic/step_adapters/stride.rb', line 11

def operation
  @operation
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/clear_logic/step_adapters/stride.rb', line 11

def options
  @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, options, args)
  @operation = operation
  @options = options
  @args = args
  @context = args.flatten.first

  options[:rescue] ||= {}

  context.step = options[:step_name]

  return success(context) if context.exit_success?

  result = operation.call(context)

  log_result

  return result if result.success?

  failure_method
rescue *Array(options[: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 = options[:rescue][error.class]
  rescue_method ? context.service.send(rescue_method, context) : failure(context)
end

#failure_methodObject



51
52
53
# File 'lib/clear_logic/step_adapters/stride.rb', line 51

def failure_method
  options[:failure] ? context.service.send(options[:failure], context) : failure(context)
end

#log_resultObject



45
46
47
48
49
# File 'lib/clear_logic/step_adapters/stride.rb', line 45

def log_result
  return unless options[:log] || context.service.class.logger_options[:log_all]

  context.service.class.logger_instance.info(context)
end