class Teckel::Operation::Runner

The default implementation for executing a single {Operation} @note You shouldn't need to call this explicitly.

Use {ClassMethods#with MyOperation.with()} or {ClassMethods#with MyOperation.call()} instead.

@!visibility protected

Constants

UNDEFINED

@!visibility private

Attributes

operation[R]
settings[R]

Public Class Methods

new(operation, settings = UNDEFINED) click to toggle source
# File lib/teckel/operation/runner.rb, line 13
def initialize(operation, settings = UNDEFINED)
  @operation, @settings = operation, settings
end

Public Instance Methods

call(input = nil) click to toggle source
# File lib/teckel/operation/runner.rb, line 18
def call(input = nil)
  catch(:halt) do
    op = instance
    op_input = op.instance_exec(input, &operation.input_constructor)
    op.call(op_input)
    nil # return values need to go through +success!+ or +fail!+
  end
end
fail!(*args) click to toggle source

Halt any further execution with an error value

@return a thing matching your {Teckel::Operation::Config#error error} definition @!visibility protected

# File lib/teckel/operation/runner.rb, line 62
def fail!(*args)
  value =
    if args.size == 1 && operation.error === args.first # rubocop:disable Style/CaseEquality
      args.first
    else
      operation.error_constructor.call(*args)
    end

  throw :halt, instance.instance_exec(value, false, &operation.result_constructor)
end
instance() click to toggle source
# File lib/teckel/operation/runner.rb, line 27
def instance
  return @instance if instance_variable_defined?(:@instance)

  op = operation.new
  op.runner = self
  op.settings = settings if settings != UNDEFINED

  @instance = op
end
success!(*args) click to toggle source

Halt any further execution with a output value

@return a thing matching your {Teckel::Operation::Config#output output} definition @!visibility protected

# File lib/teckel/operation/runner.rb, line 47
def success!(*args)
  value =
    if args.size == 1 && operation.output === args.first # rubocop:disable Style/CaseEquality
      args.first
    else
      operation.output_constructor.call(*args)
    end

  throw :halt, instance.instance_exec(value, true, &operation.result_constructor)
end
with(*) click to toggle source

This is just here to raise a meaningful error. @!visibility private

# File lib/teckel/operation/runner.rb, line 39
def with(*)
  raise Teckel::Error, "Operation already has settings assigned."
end