Harbor::Hooks::Chain
Parent
Public Class Methods
bind!(target, method_name)
# File lib/harbor/hooks.rb, line 90 90: def self.bind!(target, method_name) 91: target.send(:alias_method, "__hooked_#{method_name}", method_name) 92: 93: target.send(:class_eval, "instance_variable_set(:@__harbor_binding_method, true)\ndef \#{method_name}(*args, &block)\nself.class.hooks[\#{method_name.inspect}].call(self, args, block)\nend\nremove_instance_variable(:@__harbor_binding_method)\n") 94: end
new(target, method_name)
# File lib/harbor/hooks.rb, line 37 37: def initialize(target, method_name) 38: @target = target 39: @method_name = method_name 40: @before = [] 41: @after = [] 42: 43: if (superclass = target.superclass) && Harbor::Hooks > superclass 44: @before = superclass.hooks[method_name].before_hooks.dup 45: @after = superclass.hooks[method_name].after_hooks.dup 46: end 47: 48: bind! if target.instance_methods(false).include?(method_name.to_s) 49: end
Public Instance Methods
before(block)
# File lib/harbor/hooks.rb, line 64 64: def before(block) 65: @before << block 66: end
bind!()
# File lib/harbor/hooks.rb, line 103 103: def bind! 104: self.class.bind!(@target, @method_name) 105: end
call(instance, args, blk = nil)
# File lib/harbor/hooks.rb, line 72 72: def call(instance, args, blk = nil) 73: result = nil 74: 75: catch(:halt) do 76: @before.each do |block| 77: block.call instance 78: end 79: 80: result = instance.send("__hooked_#{@method_name}", *args, &blk) 81: 82: @after.each do |block| 83: block.call instance 84: end 85: 86: result 87: end 88: end