Dynflow/dynflow — pull request #94 by iNecas (2014-02-02 06:44:02+00:00)
Title: Middleware support

Allows defining wrappers for action methods. For example, a middleware
logging the run method might look like this:

class LogMiddleware < Dynflow::Middleware

def logger
@logger ||= Logger.new
end

def run(*args)
logger.debug "before_run: #{action.input[:message]}"
pass(*args)
ensure
logger.debug "after_run: #{action.output[:message]}"
end
end

In action, it's possible to do:

class Action < Dynflow::Action
middleware.use LogMiddleware
end

The `middleware.use` method takes addition options `:before`, `:after`
and replace allowing to determine the order of the middleware in the stack
or replace some other middleware with it.

The middlewares are combined with the middlewares of the parents.
It's also possible to specify the middlewares on world level:

world.middleware.use SomeMiddleware