Class: Jerakia::Lookup::PluginFactory
- Inherits:
-
Object
- Object
- Jerakia::Lookup::PluginFactory
- Defined in:
- lib/jerakia/lookup/pluginfactory.rb
Instance Method Summary collapse
- #create_plugin_method(name, &block) ⇒ Object
-
#initialize ⇒ PluginFactory
constructor
A new instance of PluginFactory.
- #register(name, plugin) ⇒ Object
Constructor Details
#initialize ⇒ PluginFactory
Returns a new instance of PluginFactory.
3 4 5 6 |
# File 'lib/jerakia/lookup/pluginfactory.rb', line 3 def initialize Jerakia.log.debug("Loaded plugin handler") @plugin_config = Jerakia.config[:plugins] || {} end |
Instance Method Details
#create_plugin_method(name, &block) ⇒ Object
9 10 11 |
# File 'lib/jerakia/lookup/pluginfactory.rb', line 9 def create_plugin_method(name, &block) self.class.send(:define_method, name, &block) end |
#register(name, plugin) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jerakia/lookup/pluginfactory.rb', line 13 def register(name,plugin) begin require "jerakia/lookup/plugin/#{name}" rescue LoadError => e raise Jerakia::Error, "Cannot load plugin #{name}, #{e.}" end plugin.activate(name) create_plugin_method(name) do plugin end if plugin.respond_to?('autorun') Jerakia.log.debug("Found autorun method for plugin #{name}, executing") if plugin.method('autorun').arity == 1 plugin.autorun (@plugin_config[name.to_s] || {} ) else plugin.autorun end end end |