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.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/command_kit/commands.rb', line 137 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 |command_alias| command_aliases[command_alias] = name end return subcommand end |
#command_aliases ⇒ Hash{String => String}
The registered command aliases.
98 99 100 101 102 103 104 |
# File 'lib/command_kit/commands.rb', line 98 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.
82 83 84 85 86 87 88 |
# File 'lib/command_kit/commands.rb', line 82 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.
164 165 166 167 168 169 170 171 |
# File 'lib/command_kit/commands.rb', line 164 def get_command(name) name = name.to_s name = command_aliases.fetch(name,name) if (subcommand = commands[name]) subcommand.command end end |