Class: DBGeni::Plugin
- Inherits:
-
Object
- Object
- DBGeni::Plugin
- Defined in:
- lib/dbgeni/plugin.rb
Class Attribute Summary collapse
-
.hooks ⇒ Object
readonly
Returns the value of attribute hooks.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Plugin
constructor
A new instance of Plugin.
- #load_plugin(filename) ⇒ Object
- #load_plugins(path) ⇒ Object
- #run_plugin(klass, hook, attrs) ⇒ Object
- #run_plugins(hook, attrs) ⇒ Object
Constructor Details
permalink #initialize ⇒ Plugin
Returns a new instance of Plugin.
43 44 |
# File 'lib/dbgeni/plugin.rb', line 43 def initialize end |
Class Attribute Details
permalink .hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
4 5 6 |
# File 'lib/dbgeni/plugin.rb', line 4 def hooks @hooks end |
Class Method Details
permalink .install_plugin(hook, klass) ⇒ Object
[View source]
6 7 8 9 10 11 |
# File 'lib/dbgeni/plugin.rb', line 6 def install_plugin(hook, klass) unless @hooks.has_key? hook raise DBGeni::InvalidHook end @hooks[hook].push klass end |
permalink .reset ⇒ Object
[View source]
13 14 15 16 17 |
# File 'lib/dbgeni/plugin.rb', line 13 def reset @hooks.keys.each do |k| @hooks[k] = Array.new end end |
Instance Method Details
permalink #load_plugin(filename) ⇒ Object
[View source]
57 58 59 |
# File 'lib/dbgeni/plugin.rb', line 57 def load_plugin(filename) require filename end |
permalink #load_plugins(path) ⇒ Object
[View source]
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dbgeni/plugin.rb', line 46 def load_plugins(path) begin files = Dir.entries(path).grep(/\.rb$/).sort rescue Errno::ENOENT, Errno::EACCES => e raise DBGeni::PluginDirectoryNotAccessible, e.to_s end files.each do |f| load_plugin File.join(path, f) end end |
permalink #run_plugin(klass, hook, attrs) ⇒ Object
[View source]
72 73 74 75 76 77 78 |
# File 'lib/dbgeni/plugin.rb', line 72 def run_plugin(klass, hook, attrs) instance = klass.new unless instance.respond_to? :run raise DBGeni::PluginDoesNotRespondToRun end instance.run(hook, attrs) end |
permalink #run_plugins(hook, attrs) ⇒ Object
[View source]
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dbgeni/plugin.rb', line 61 def run_plugins(hook, attrs) klasses = self.class.hooks[hook] unless klasses.is_a? Array raise DBGeni::InvalidHook, hook end klasses.each do |k| run_plugin k, hook, attrs end end |