Module: Disbatch::Plugin
Defined Under Namespace
Modules: Hello
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Return a plugin by name.
-
#exists?(name) ⇒ Boolean
Check for existance of plugin.
-
#init(file) ⇒ Object
Attempt to load a plugin file.
-
#init_all(glob) ⇒ Object
Attempt to load all plugin files matched by a glob.
-
#register(plugin) ⇒ Object
Register a class as a plugin.
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
3 4 5 |
# File 'lib/disbatch/plugin.rb', line 3 def plugins @plugins end |
Instance Method Details
#[](name) ⇒ Object
Return a plugin by name
18 19 20 21 |
# File 'lib/disbatch/plugin.rb', line 18 def [](name) raise Disbatch::NoPluginError unless @plugins.has_key?(name) @plugins[name] end |
#exists?(name) ⇒ Boolean
Check for existance of plugin
24 25 26 |
# File 'lib/disbatch/plugin.rb', line 24 def exists?(name) @plugins.has_key?(name) end |
#init(file) ⇒ Object
Attempt to load a plugin file
29 30 31 32 33 34 35 |
# File 'lib/disbatch/plugin.rb', line 29 def init(file) begin load file rescue => e raise Disbatch::FailedLoadPluginError, file end end |
#init_all(glob) ⇒ Object
Attempt to load all plugin files matched by a glob
38 39 40 |
# File 'lib/disbatch/plugin.rb', line 38 def init_all(glob) Dir[glob].each { |file| init(file) } end |
#register(plugin) ⇒ Object
Register a class as a plugin
8 9 10 11 12 13 14 15 |
# File 'lib/disbatch/plugin.rb', line 8 def register(plugin) name = plugin.to_s raise Disbatch::InvalidPluginError unless plugin.respond_to?(:execute) @plugins[name] = plugin puts "Registered #{name}" end |