diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2008-06-10 15:08:44 -0700 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2008-07-23 21:01:43 -0700 |
commit | 04434cd6efa5665a983a2b8acde20b898fcf28c0 (patch) | |
tree | 7bd4b34a31fff258f29bf534cd344d2b0b3f395d /lib/redmine/plugin.rb | |
parent | fe22ef95a8d80f9189d741b020f6d0df6ef61183 (diff) | |
download | redmine-04434cd6efa5665a983a2b8acde20b898fcf28c0.tar.gz redmine-04434cd6efa5665a983a2b8acde20b898fcf28c0.zip |
Changed Hook API to use a Manager class. #1296
Diffstat (limited to 'lib/redmine/plugin.rb')
-rw-r--r-- | lib/redmine/plugin.rb | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 3a0375bb1..2366c49ff 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -118,7 +118,7 @@ module Redmine #:nodoc: end def add_hook(hook_name, method) - Redmine::Plugin::Hook.add_listener(hook_name, method) + Redmine::Plugin::Hook::Manager.add_listener(hook_name, method) end # Returns +true+ if the plugin can be configured. @@ -128,51 +128,56 @@ module Redmine #:nodoc: # TODO: Doc class Hook - - # Hooks and the procs added - @@hooks = { - :issue_show => [], - :issue_edit => [], - :issue_bulk_edit => [], - :issue_bulk_edit_save => [], - :issue_update => [], - :project_member_list_header => [], - :project_member_list_column_three => [], - :issues_helper_show_details => [] - } + class Manager + # Hooks and the procs added + @@hooks = { + :issue_show => [], + :issue_edit => [], + :issue_bulk_edit => [], + :issue_bulk_edit_save => [], + :issue_update => [], + :project_member_list_header => [], + :project_member_list_column_three => [], + :issues_helper_show_details => [] + } - cattr_reader :hooks + cattr_reader :hooks - class << self + class << self - # TODO: Doc - def valid_hook?(hook_name) - return @@hooks.has_key?(hook_name) - end + # TODO: Doc + def valid_hook?(hook_name) + return @@hooks.has_key?(hook_name) + end - # TODO: Doc - def add_listener(hook_name, method) - if valid_hook?(hook_name) - @@hooks[hook_name.to_sym] << method - puts "Listener added for #{hook_name.to_s}" + # TODO: Doc + def add_listener(hook_name, method) + if valid_hook?(hook_name) + @@hooks[hook_name.to_sym] << method + puts "Listener added for #{hook_name.to_s}" + end end - end - # TODO: Doc - def call_hook(hook_name, context = { }) - response = '' - @@hooks[hook_name.to_sym].each do |method| - response += method.call(context) + # TODO: Doc + def call_hook(hook_name, context = { }) + response = '' + @@hooks[hook_name.to_sym].each do |method| + response += method.call(context) + end + response end - response - end - # TODO: Doc - def hook_registered?(hook_name) - return @@hooks[hook_name.to_sym].size > 0 + # TODO: Doc + def hook_registered?(hook_name) + return @@hooks[hook_name.to_sym].size > 0 + end end end - + + # Default class for Hooks to subclass + class Base + + end end end end |