Module: Disbatch::Plugin

Extended by:
Plugin
Included in:
Plugin
Defined in:
lib/disbatch/plugin.rb

Defined Under Namespace

Modules: Hello

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pluginsObject (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

Returns:

  • (Boolean)


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

Raises:

  • (Disbatch::InvalidPluginError)


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