Class: Sh::Plugin
Class Attribute Summary collapse
-
.active_plugins ⇒ Object
readonly
Returns the value of attribute active_plugins.
-
.registered_plugins ⇒ Object
readonly
Returns the value of attribute registered_plugins.
Class Method Summary collapse
- .broadcast(method_name, *args) ⇒ Object
- .define(id_name, &block) ⇒ Object
- .init ⇒ Object
- .save_prefs ⇒ Object
Methods included from PluginSugar
Class Attribute Details
.active_plugins ⇒ Object (readonly)
Returns the value of attribute active_plugins.
31 32 33 |
# File 'lib/sh_plugin.rb', line 31 def active_plugins @active_plugins end |
.registered_plugins ⇒ Object (readonly)
Returns the value of attribute registered_plugins.
31 32 33 |
# File 'lib/sh_plugin.rb', line 31 def registered_plugins @registered_plugins end |
Class Method Details
.broadcast(method_name, *args) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/sh_plugin.rb', line 44 def self.broadcast(method_name, *args) active_plugins.each_value do |plugin| if plugin.respond_to? method_name Thread.new {plugin.send method_name, *args} end end end |
.define(id_name, &block) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sh_plugin.rb', line 35 def self.define(id_name, &block) p = new p.id_name id_name p.instance_eval(&block) p.init @plugin_prefs[id_name] if p.respond_to? :init registered_plugins[id_name] = p active_plugins[id_name] = p end |
.init ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/sh_plugin.rb', line 22 def self.init begin @plugin_prefs = YAML.load_file(Sh::Global::PATHS[:plugin_prefs_file]) rescue @plugin_prefs = {} end end |
.save_prefs ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sh_plugin.rb', line 52 def self.save_prefs prefs = {} registered_plugins.each do |id, plugin| if plugin.respond_to? :preferences prefs[id] = plugin.preferences end end open(Sh::Global::PATHS[:plugin_prefs_file], "w") do |f| f.write prefs.to_yaml end end |