class CfScript::Command::Registry
Constants
- DuplicateCommand
- UnimplementedCommand
Attributes
commands[R]
Public Class Methods
new()
click to toggle source
# File lib/cf_script/command/registry.rb, line 8 def initialize @commands = {} end
Public Instance Methods
[](command_name)
click to toggle source
# File lib/cf_script/command/registry.rb, line 46 def [](command_name) commands[command_name] end
add!(command_class)
click to toggle source
# File lib/cf_script/command/registry.rb, line 22 def add!(command_class) instance = command_class.instance if known?(instance.name) raise DuplicateCommand.new( "The '#{instance.name}' command is already registered" ) end commands[instance.name] = instance end
catalog()
click to toggle source
# File lib/cf_script/command/registry.rb, line 12 def catalog catalog = Hash.new { |types, type| types[type] = [] } commands.each do |name, command| catalog[command.type] << name end catalog end
check!(command_name)
click to toggle source
# File lib/cf_script/command/registry.rb, line 38 def check!(command_name) unless known?(command_name) raise UnimplementedCommand.new( "The #{command_name} command is not implemented, yet" ) end end
known?(command_name)
click to toggle source
# File lib/cf_script/command/registry.rb, line 34 def known?(command_name) commands.key?(command_name) end