Module: Rig::Plugin

Defined in:
lib/rig/plugin.rb

Defined Under Namespace

Modules: Base

Class Method Summary collapse

Class Method Details

.load(plugins = { }) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rig/plugin.rb', line 20

def load(plugins={ })
  plugins.each do |plugin, data|
    begin
      f = "#{Rig::Config.dir}/plugins/#{plugin}"
      Rig::Log.debug "loading plugin: #{plugin} #{f}"
      require f
    rescue LoadError, StandardError => e
      Rig::Log.error "error while loading plugin: #{plugin}: #{e.message} at #{e.backtrace.first}"
    end
  end
end

.on(klass, event, &block) ⇒ Object



15
16
17
18
# File 'lib/rig/plugin.rb', line 15

def on(klass, event, &block)
  @hooks ||= []
  @hooks << { :event => event, :class => klass, :block => block }
end

.run(event, *args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/rig/plugin.rb', line 4

def run(event, *args)
  @hooks ||= []
  @hooks.select { |e| e[:event] == event }.each do |plugin|
    klass = plugin[:class]
    block = plugin[:block]

    Rig::Log.debug "calling #{klass} :: #{event}"
    block.call(args.dup)
  end
end