Added documentation
This commit is contained in:
1 parent
8995245a0c
commit
08058e6a02
1 file changed
+13
-5
+13
-5
@@ -117,6 +117,14 @@ module Redmine #:nodoc:
|
|||||||
@project_module = nil
|
@project_module = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Registers a +method+ to be called when Redmine runs a hook called
|
||||||
|
# +hook_name+
|
||||||
|
#
|
||||||
|
# # Run puts whenever the issue_show hook is called
|
||||||
|
# add_hook :issue_show, Proc.new { puts 'Hello' }
|
||||||
|
#
|
||||||
|
# # Call the class method +my_method+ passing in all the context
|
||||||
|
# add_hook :issue_show, Proc.new {|context| MyPlugin.my_method(context)}
|
||||||
def add_hook(hook_name, method)
|
def add_hook(hook_name, method)
|
||||||
Redmine::Plugin::Hook::Manager.add_listener(hook_name, method)
|
Redmine::Plugin::Hook::Manager.add_listener(hook_name, method)
|
||||||
end
|
end
|
||||||
@@ -126,7 +134,8 @@ module Redmine #:nodoc:
|
|||||||
settings && settings.is_a?(Hash) && !settings[:partial].blank?
|
settings && settings.is_a?(Hash) && !settings[:partial].blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Doc
|
# Hook is used to allow plugins to hook into Redmine at specific sections
|
||||||
|
# to change it's behavior. See +Redmine::Plugin.add_hook+ for details.
|
||||||
class Hook
|
class Hook
|
||||||
class Manager
|
class Manager
|
||||||
# Hooks and the procs added
|
# Hooks and the procs added
|
||||||
@@ -145,12 +154,11 @@ module Redmine #:nodoc:
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# TODO: Doc
|
|
||||||
def valid_hook?(hook_name)
|
def valid_hook?(hook_name)
|
||||||
return @@hooks.has_key?(hook_name)
|
return @@hooks.has_key?(hook_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Doc
|
# Add +method+ to +hook_name+
|
||||||
def add_listener(hook_name, method)
|
def add_listener(hook_name, method)
|
||||||
if valid_hook?(hook_name)
|
if valid_hook?(hook_name)
|
||||||
@@hooks[hook_name.to_sym] << method
|
@@hooks[hook_name.to_sym] << method
|
||||||
@@ -158,7 +166,7 @@ module Redmine #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Doc
|
# Run all the hooks for +hook_name+ passing in +context+
|
||||||
def call_hook(hook_name, context = { })
|
def call_hook(hook_name, context = { })
|
||||||
response = ''
|
response = ''
|
||||||
@@hooks[hook_name.to_sym].each do |method|
|
@@hooks[hook_name.to_sym].each do |method|
|
||||||
@@ -167,7 +175,7 @@ module Redmine #:nodoc:
|
|||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Doc
|
# Are hooks registered for +hook_name+
|
||||||
def hook_registered?(hook_name)
|
def hook_registered?(hook_name)
|
||||||
return @@hooks[hook_name.to_sym].size > 0
|
return @@hooks[hook_name.to_sym].size > 0
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user