Module: Rig::Plugin
- Defined in:
- lib/rig/plugin.rb
Defined Under Namespace
Modules: Base
Class Method Summary collapse
Class Method Details
.load(plugins = { }) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rig/plugin.rb', line 23 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.} at #{e.backtrace.first}" end end end |
.on(klass, event, &block) ⇒ Object
18 19 20 21 |
# File 'lib/rig/plugin.rb', line 18 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 14 15 16 |
# 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] begin Rig::Log.debug "calling #{klass} :: #{event}" block.call(args.dup) rescue => e Rig::Log.error "failed to run event #{event} for #{klass}" end end end |