Class: Linen::PluginRegistry
- Inherits:
-
Object
- Object
- Linen::PluginRegistry
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/linen/plugin_registry.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #commands ⇒ Object
- #each ⇒ Object
- #find_command(name) ⇒ Object
- #register_plugin(plugin) ⇒ Object (also: #register, #<<)
- #size ⇒ Object
Instance Method Details
#[](name) ⇒ Object
48 49 50 |
# File 'lib/linen/plugin_registry.rb', line 48 def []( name ) return @plugins[ name ] end |
#commands ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/linen/plugin_registry.rb', line 53 def commands if @commands.nil? ### create @commands. Each new key will get an empty array as its default value. @commands = IndifferentHash.new ### populates @commands as a hash of arrays. The hash key is the command name (.to_s) and the value ### is an array containing each plugin class in which that command is defined. @plugins.each do |name, plugin| plugin.commands.each do |name, cmd| @commands[ name ] ||= [] @commands[ name ] << plugin end end end return @commands end |
#each ⇒ Object
26 27 28 29 |
# File 'lib/linen/plugin_registry.rb', line 26 def each ### yield the actual plugin object, which knows its own name @plugins.each { |name, plugin| yield plugin } end |
#find_command(name) ⇒ Object
72 73 74 |
# File 'lib/linen/plugin_registry.rb', line 72 def find_command( name ) return @commands[ name ] end |
#register_plugin(plugin) ⇒ Object Also known as: register, <<
32 33 34 35 36 37 38 |
# File 'lib/linen/plugin_registry.rb', line 32 def register_plugin( plugin ) raise Linen::Plugin::ArgumentError, "Attempted to register something that is not a Linen::Plugin" unless plugin < Linen::Plugin @plugins ||= {} @plugins[ plugin.short_name ] = plugin end |
#size ⇒ Object
43 44 45 |
# File 'lib/linen/plugin_registry.rb', line 43 def size return @plugins.size end |