Module: CommandKit::Commands::ClassMethods
- Defined in:
- lib/command_kit/commands.rb
Overview
Class-level methods.
Instance Method Summary collapse
-
#command(name = nil, command_class, **kwargs) ⇒ Subcommand
Mounts a command as a sub-command.
-
#command_aliases ⇒ Hash{String => String}
The registered command aliases.
-
#commands ⇒ Hash{String => Subcommand}
The registered sub-commands.
-
#get_command(name) ⇒ Class#main?
private
Gets the command.
Instance Method Details
#command(name = nil, command_class, **kwargs) ⇒ Subcommand
Mounts a command as a sub-command.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/command_kit/commands.rb', line 144 def command(name=nil, command_class, **kwargs) name = if name then name.to_s else command_class.command_name end subcommand = Subcommand.new(command_class,**kwargs) commands[name] = subcommand subcommand.aliases.each do |alias_name| command_aliases[alias_name] = name end return subcommand end |
#command_aliases ⇒ Hash{String => String}
The registered command aliases.
105 106 107 108 109 110 111 |
# File 'lib/command_kit/commands.rb', line 105 def command_aliases @command_aliases ||= if superclass.kind_of?(ClassMethods) superclass.command_aliases.dup else {} end end |
#commands ⇒ Hash{String => Subcommand}
The registered sub-commands.
89 90 91 92 93 94 95 |
# File 'lib/command_kit/commands.rb', line 89 def commands @commands ||= if superclass.kind_of?(ClassMethods) superclass.commands.dup else {} end end |
#get_command(name) ⇒ Class#main?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets the command.
170 171 172 173 174 175 176 177 |
# File 'lib/command_kit/commands.rb', line 170 def get_command(name) name = name.to_s name = command_aliases.fetch(name,name) if (subcommand = commands[name]) subcommand.command end end |