Class: Plugman

Inherits:
Object
  • Object
show all
Defined in:
lib/plugman.rb,
lib/plugman/version.rb,
lib/plugman/plugin_base.rb,
lib/plugman/config_loader.rb

Defined Under Namespace

Classes: ConfigLoader, PluginBase

Constant Summary collapse

VERSION =
"1.0.2"

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Plugman

Returns a new instance of Plugman.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/plugman.rb', line 9

def initialize(args)
  Plugman::PluginBase.manager = self

  @plugins = args[:plugins] || []
  @logger  = args[:logger]
  @loader  = args[:loader]

  if @logger.nil?
    @logger = Logger.new(STDERR)
    @logger.level = Logger::WARN
  end
end

Instance Method Details

#load_pluginsObject



22
23
24
# File 'lib/plugman.rb', line 22

def load_plugins
  @loader.call(@logger)
end

#notify(event, *arguments, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/plugman.rb', line 26

def notify(event, *arguments, &block)
  @logger.debug("Sending #{event} to plugins")
  @plugins.select {|p| p.respond_to?(event)}.each do |p|
    notify_plugin(p, event, *arguments, &block)
  end
  true
end

#register_plugin(klass) ⇒ Object

Called from Plugman::PluginBase when inherited



35
36
37
# File 'lib/plugman.rb', line 35

def register_plugin(klass)
  @plugins.push(klass.new)
end