class Architect::PluginManager

Attributes

log[RW]
pluginconfigdir[RW]

The path to the configuration directory for plugins. Each plugin gets it’s own configuration file with the same name as the plugin.

plugins[R]

Public Class Methods

new(config) click to toggle source
# File lib/architect/plugin_manager.rb, line 13
def initialize(config)
  @config = config.to_hash
  @pluginconfigdir = '/etc/architect/plugin.d/'
  @log = Architect::Log.log
  #log.level = Logger::DEBUG
  @plugins = OpenStruct.new
  plugindir =  File.dirname(__FILE__) + '/plugin'
  log.debug "registering plugins in #{plugindir}"
  Dir.glob("#{plugindir}/*.rb").each do |pluginfile|
    load pluginfile
  end
  register_all_plugins
  plugins.each do |plugin|
    conffile = "#{pluginconfigdir}/#{plugin.name}.yaml"
    if File.exist? conffile
      plugin.configure Architect::Config.symbolize_hash YAML.load(conffile)
    end
  end
end

Public Instance Methods

unregister_all() click to toggle source

Before the program exist, each plugin is unregistered. This gives it a chance to clean up.

# File lib/architect/plugin_manager.rb, line 35
def unregister_all
  raise 'FIXME - STUB'
end

Private Instance Methods

load(pluginfile) click to toggle source
# File lib/architect/plugin_manager.rb, line 43
def load(pluginfile)
  log.debug "loading #{pluginfile}"
  begin
    require pluginfile
  rescue
    log.warn "plugin failed to load: #{pluginfile}"
  end
end
register_all_plugins() click to toggle source

Instantiate all plugins

# File lib/architect/plugin_manager.rb, line 53
def register_all_plugins
  ObjectSpace.each_object(Class) do |klass|
    if klass < Architect::Plugin
      plugin = klass.new
      name = plugin.name.to_sym
      @plugins[name] = plugin
      log.debug "registered #{klass} as #{name}"
    end
  end
end