Module | Innate::Helper::Aspect |
In: |
lib/innate/helper/aspect.rb
|
Provides before/after wrappers for actions
This helper is essential for proper working of {Action#render}.
AOP | = | Hash.new{|h,k| h[k] = Hash.new{|hh,kk| hh[kk] = {} }} |
This awesome piece of hackery implements action AOP.
The so-called aspects are simply methods that may yield the next aspect in the chain, this is similar to racks concept of middleware, but instead of initializing with an app we simply pass a block that may be yielded with the action being processed.
This gives us things like logging, caching, aspects, authentication, etc.
Add the name of your method to the trait[:wrap] to add your own method to the wrap_action_call chain.
@example adding your method
class MyNode Innate.node '/' private def wrap_logging(action) Innate::Log.info("Executing #{action.name}") yield end trait[:wrap] end
methods may register themself in the trait[:wrap] and will be called in left-to-right order, each being passed the action instance and a block that they have to yield to continue the chain.
@param [Action] action instance that is being passed to every registered method @param [Proc] block contains the instructions to call the action method if any
@see Action#render @author manveru