Class: Linen::PluginRegistry

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Singleton
Defined in:
lib/linen/plugin_registry.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



38
39
40
# File 'lib/linen/plugin_registry.rb', line 38

def []( name )
	return @plugins[ name ]
end

#commandsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/linen/plugin_registry.rb', line 43

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

#eachObject



16
17
18
19
# File 'lib/linen/plugin_registry.rb', line 16

def each
	### yield the actual plugin object, which knows its own name
	@plugins.each { |name, plugin| yield plugin }
end

#find_command(name) ⇒ Object



62
63
64
# File 'lib/linen/plugin_registry.rb', line 62

def find_command( name )
	return @commands[ name ]
end

#register_plugin(plugin) ⇒ Object Also known as: register, <<



22
23
24
25
26
27
28
# File 'lib/linen/plugin_registry.rb', line 22

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

#sizeObject



33
34
35
# File 'lib/linen/plugin_registry.rb', line 33

def size
	return @plugins.size
end