Module: Hookable
- Included in:
- Commands::Runners::Runner
- Defined in:
- lib/hookable.rb
Overview
- Copyright
-
Copyright © 2005 Nicolas Pouillard. All rights reserved.
- Author
-
Nicolas Pouillard <[email protected]>.
- License
-
Gnu General Public License.
- Revision
-
$Id: /w/fey/ruby_ex/trunk/lib/hookable.rb 8047 2005-12-31T15:56:23.983963Z ertai $
Defined Under Namespace
Classes: HashWithRecursiveCloneDup, ProcHooker
Class Method Summary collapse
Class Method Details
.included(aClass) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hookable.rb', line 8 def self.included ( aClass ) super aClass.module_eval do def self.inheritable_attributes if @inheritable_attributes.nil? or @inheritable_attributes.empty? @inheritable_attributes = HashWithRecursiveCloneDup.new end @inheritable_attributes end class_inheritable_array :hooks class_inheritable_array :hookers inheritable_attributes[:hookers] = [] inheritable_attributes[:hooks] = [] def hook_trigger ( name, *args ) return if defined? @disabled_hooks and @disabled_hooks.include? name return if defined? @@disabled_hooks and @@disabled_hooks.include? name self.class.hook_trigger(name, *args) return unless defined? @hookers @hookers.each do |hooker| @@hook_trigger_internal[hooker, name, *args] end end def self.hook_trigger ( name, *args ) raise ArgumentError, "Unknown hook #{name}" unless hooks.include? name return if defined? @@disabled_hooks and @@disabled_hooks.include? name hookers.each do |hooker| @@hook_trigger_internal[hooker, name, *args] end end def self.hooker_subscribe ( hooker ) hookers << hooker end def hooker_subscribe ( hooker ) @hookers ||= [] @hookers << hooker end def self.subscribe_hook ( *hook_names, &block ) hooker_subscribe ProcHooker.new(*hook_names, &block) end def subscribe_hook ( *hook_names, &block ) hooker_subscribe ProcHooker.new(*hook_names, &block) end def disable_hook ( *hook_names ) @disabled_hooks ||= [] @disabled_hooks = @disabled_hooks + hook_names end def self.disable_hook ( *hook_names ) @@disabled_hooks ||= [] @@disabled_hooks = @@disabled_hooks + hook_names end def self.hook_declare ( name, *groups ) hooks << name end @@hook_trigger_internal = lambda do |hooker, name, *args| if hooker.respond_to?(name) hooker.send(name, *args) else if hooker.respond_to? :default_hook and not hooker.default_hook.nil? hooker.send(hooker.default_hook, name, *args) elsif hooker.respond_to?(:method_missing) hooker.send(name, *args) end end end end end |