class HareDo::Plugins::Manager

This class loads Ruby files/modules into private namespaces. That is, they are not globally visible.

Example:

instance = Plugins::Manager.load("#{@path}/plugin")
mod = instance.get('Sonar')
plugin = mod::Plugin.new(@config)

plugins[plugin.uuid] = plugin

Attributes

environment[RW]
loaded[R]
module_path_prefix[RW]

Public Class Methods

new(peer) click to toggle source
# File src/lib/haredo/peer.rb, line 102
def initialize(peer)
  @peer        = peer
  @loaded      = {}
  @config      = {}
  @environment = {}
  @trace       = false

  @module_path_prefix = 'haredo/plugins'
end

Public Instance Methods

[](name) click to toggle source
# File src/lib/haredo/peer.rb, line 112
def [](name)
  return @loaded[name]
end
load(plugin_name, base=@module_path_prefix) click to toggle source
# File src/lib/haredo/peer.rb, line 124
def load(plugin_name, base=@module_path_prefix)
  
  # Iterate through the RUBY_PATH looking for a match
  $:.each do |dir|
    path = "#{dir}/#{base}/#{plugin_name}.rb"
    if File.exists? path
      instance = Instance.new(path)
      cls = instance.get('Plugin')
      plugin = cls.new(@peer, @config[cls::UUID], @environment)
      @loaded[plugin.uuid] = plugin
      $stderr.puts "Loaded plugin #{path}"

      return
    end
  end
end
loadConfig(config) click to toggle source
# File src/lib/haredo/peer.rb, line 116
def loadConfig(config)
  @config.merge! config

  config.each do |plugin_name, value|
    load(plugin_name)
  end
end
process(msg) click to toggle source

Process a message. Looks up module by given by UUID in headers. If found, passes message off to it.

# File src/lib/haredo/peer.rb, line 143
def process(msg)
  uuid = msg.headers['uuid']

  if @loaded.has_key?(uuid)
    @loaded[uuid].process(msg)
  end
end
shutdown() click to toggle source
# File src/lib/haredo/peer.rb, line 151
def shutdown()
  @loaded.each do|uuid, plugin|
    plugin.finalize()
  end
end