Module: Extlib::Hook::ClassMethods

Module | Extlib::Hook::ClassMethods
In: | lib/extlib/hook.rb

### Methods

after after_class_method args_for before before_class_method class_hooks define_advised_method define_hook_stack_execution_methods hook_method_name hooks_with_scope inline_call install_hook instance_hooks method_with_scope process_method_added quote_method register_class_hooks register_hook register_instance_hooks registered_as_hook? reset_hook!

### Included Modules

Extlib::Assertions

### Public Instance methods

after(target_method, method_sym = nil, &block)

Inject code that executes after the target instance method.

@param target_method<Symbol> the name of the instance method to inject after @param method_sym<Symbol> the name of the method to run after the

      target_method

@param block<Block> the code to run after the target_method

@note

      Either method_sym or block is required.

- @api public

after_class_method(target_method, method_sym = nil, &block)

Inject code that executes after the target class method.

@param target_method<Symbol> the name of the class method to inject after @param method_sym<Symbol> the name of the method to run after the target_method @param block<Block> the code to run after the target_method

@note

      Either method_sym or block is required.

- @api public

args_for(method)

— Helpers —

before(target_method, method_sym = nil, &block)

Inject code that executes before the target instance method.

@param target_method<Symbol> the name of the instance method to inject before @param method_sym<Symbol> the name of the method to run before the

      target_method

@param block<Block> the code to run before the target_method

@note

      Either method_sym or block is required.

- @api public

before_class_method(target_method, method_sym = nil, &block)

Inject code that executes before the target class method.

@param target_method<Symbol> the name of the class method to inject before @param method_sym<Symbol> the name of the method to run before the

      target_method

@param block<Block> the code to run before the target_method

@note

      Either method_sym or block is required.

- @api public

class_hooks()
define_advised_method(target_method, scope)
define_hook_stack_execution_methods(target_method, scope)

Defines two methods. One method executes the before hook stack. The other executes the after hook stack. This method will be called many times during the Class definition process. It should be called for each hook that is defined. It will also be called when a hook is redefined (to make sure that the arity hasn‘t changed).

hook_method_name(target_method, prefix, suffix)

Generates names for the various utility methods. We need to do this because the various utility methods should not end in = so, while we‘re at it, we might as well get rid of all punctuation.

hooks_with_scope(scope)

Returns the correct HOOKS Hash depending on whether we are working with class methods or instance methods

inline_call(method_info, scope)

Returns ruby code that will invoke the hook. It checks the arity of the hook method and passes arguments accordingly.

install_hook(type, target_method, method_sym, scope, &block)

— Add a hook —

instance_hooks()
method_with_scope(name, scope)
process_method_added(method_name, scope)

This will need to be refactored

quote_method(name)
register_class_hooks(*hooks)

Register a class method as hookable. Registering a method means that before hooks will be run immediately before the method is invoked and after hooks will be called immediately after the method is invoked.

@param hookable_method<Symbol> The name of the class method that should

      be hookable

- @api public

register_hook(target_method, scope)

Registers a method as hookable. Registering hooks involves the following process

- Create a blank entry in the HOOK Hash for the method.
- Define the methods that execute the before and after hook stack. These methods will be no-ops at first, but everytime a new hook is defined, the methods will be redefined to incorporate the new hook.
- Redefine the method that is to be hookable so that the hook stacks are invoked approprietly.

register_instance_hooks(*hooks)

Register aninstance method as hookable. Registering a method means that before hooks will be run immediately before the method is invoked and after hooks will be called immediately after the method is invoked.

@param hookable_method<Symbol> The name of the instance method that should

      be hookable

- @api public

registered_as_hook?(target_method, scope)

Is the method registered as a hookable in the given scope.

reset_hook!(target_method, scope)

Not yet implemented

[Validate]