Module: Mystro::Plugin
- Defined in:
- lib/mystro/plugin.rb
Defined Under Namespace
Modules: Base
Class Method Summary collapse
- .disabled?(name) ⇒ Boolean
- .jobs ⇒ Object
- .load(plugins = { }) ⇒ Object
- .on(klass, event, &block) ⇒ Object
- .register(key, opts = {}) ⇒ Object
- .run(event, *args) ⇒ Object
- .schedule ⇒ Object
- .ui ⇒ Object
Class Method Details
.disabled?(name) ⇒ Boolean
39 40 41 42 |
# File 'lib/mystro/plugin.rb', line 39 def disabled?(name) Mystro::Log.debug "disabled? #{name}" Mystro.config.plugins && Mystro.config.plugins.disabled && Mystro.config.plugins.disabled[name] end |
.jobs ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mystro/plugin.rb', line 64 def jobs @jobs ||= begin jobs = {} (@plugins||{}).each do |key, opts| if opts[:jobs] jobs[key] = opts[:jobs] end end jobs end end |
.load(plugins = { }) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mystro/plugin.rb', line 26 def load(plugins={ }) list = plugins.reject {|k, v| k == 'disabled'} list.each do |plugin, data| begin f = "#{Mystro.directory}/plugins/#{plugin}" Mystro::Log.debug "loading plugin: #{plugin} #{f}" require f rescue LoadError, StandardError => e Mystro::Log.error "error while loading plugin: #{plugin}: #{e.message} at #{e.backtrace.first}" end end end |
.on(klass, event, &block) ⇒ Object
21 22 23 24 |
# File 'lib/mystro/plugin.rb', line 21 def on(klass, event, &block) @hooks ||= [] @hooks << { :event => event, :class => klass, :block => block } end |
.register(key, opts = {}) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/mystro/plugin.rb', line 44 def register(key, opts={}) @plugins ||= {} @plugins[key] = opts name = key.to_s.capitalize @plugins[key][:name] = name end |
.run(event, *args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mystro/plugin.rb', line 4 def run(event, *args) return if Mystro.config.mock @hooks ||= [] @hooks.select { |e| e[:event] == event }.each do |plugin| klass = plugin[:class] block = plugin[:block] begin Mystro::Log.debug "calling #{klass} :: #{event}" block.call(args.dup) rescue => e Mystro::Log.error "failed to run event #{event} for #{klass}: #{e.message}" Mystro::Log.debug e end end end |
.schedule ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mystro/plugin.rb', line 76 def schedule @schedule ||= begin s = {} (@plugins||{}).each do |key, opts| if opts[:schedule] opts[:schedule].each do |w, o| n = w.to_s.capitalize + "Worker" s[n] = { "cron" => o} end end end s end end |
.ui ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mystro/plugin.rb', line 51 def ui @ui ||= begin ui = {} (@plugins||{}).each do |key, opts| if opts[:ui] n = opts[:name] ui[n] = opts[:ui] end end ui end end |