module Startback::Support::OperationRunner::ClassMethods

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

Public Instance Methods

around_run(arounder = nil, &bl) click to toggle source

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
# 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

Private Instance Methods

arounds(create = false) click to toggle source
# File lib/startback/support/operation_runner.rb, line 82
def arounds(create = false)
  if create
    @arounds ||= superclass.respond_to?(:arounds, true) \
               ? superclass.send(:arounds, true).dup \
               : []
  end
  @arounds || (superclass.respond_to?(:arounds, true) ? superclass.send(:arounds, true) : [])
end