Class: Rockbox::PluginRegistry
- Inherits:
-
Object
- Object
- Rockbox::PluginRegistry
- Defined in:
- lib/rockbox/plugin.rb
Instance Method Summary collapse
-
#initialize ⇒ PluginRegistry
constructor
A new instance of PluginRegistry.
- #installed?(name) ⇒ Boolean
- #list ⇒ Object
- #register(plugin, context) ⇒ Object
- #unregister(name) ⇒ Object
Constructor Details
#initialize ⇒ PluginRegistry
Returns a new instance of PluginRegistry.
31 32 33 34 |
# File 'lib/rockbox/plugin.rb', line 31 def initialize @plugins = {} @lock = Mutex.new end |
Instance Method Details
#installed?(name) ⇒ Boolean
52 53 54 |
# File 'lib/rockbox/plugin.rb', line 52 def installed?(name) @lock.synchronize { @plugins.key?(name.to_s) } end |
#list ⇒ Object
56 57 58 |
# File 'lib/rockbox/plugin.rb', line 56 def list @lock.synchronize { @plugins.values.dup } end |
#register(plugin, context) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/rockbox/plugin.rb', line 36 def register(plugin, context) name = plugin.name.to_s @lock.synchronize do raise ArgumentError, "Plugin #{name.inspect} is already installed" if @plugins.key?(name) end plugin.install(context) @lock.synchronize { @plugins[name] = plugin } plugin end |
#unregister(name) ⇒ Object
46 47 48 49 50 |
# File 'lib/rockbox/plugin.rb', line 46 def unregister(name) plugin = @lock.synchronize { @plugins.delete(name.to_s) } plugin&.uninstall if plugin.respond_to?(:uninstall) plugin end |