Module: Startback::Support::OperationRunner::ClassMethods

Defined in:
lib/startback/support/operation_runner.rb

Overview

Contributes the hook DSL methods to classes that include the OperationRunner module

Instance Method Summary collapse

Instance Method Details

#around_run(arounder = nil, &bl) ⇒ Object

Registers a callable to be executed around operation running.

In its block form, the callable is ‘instance_exec`uted on the runner instance, with the operation passed as first parameter and a then_block callable as second parameter (continuation):

around_run do |op,then_block|
  # do whatever you want with the op (already bounded)
  puts op.inspect

  # do not forget to call the continuation block
  then_block.call
end

With a parameter responding to ‘#call`, the latter is invoked with the operation as parameter and a block as continuation:

class Arounder

  def call(op)
    # do whatever you want with the op (already bounded)
    puts op.inspect

    # do not forget to call the continuation block
    yield
  end

end

Raises:

  • (ArgumentError)


75
76
77
78
# File 'lib/startback/support/operation_runner.rb', line 75

def around_run(arounder = nil, &bl)
  raise ArgumentError, "Arg or block required" unless arounder || bl
  arounds(true) << [arounder || bl, arounder.nil?]
end