class CommandKit::Commands::AutoLoad::Subcommand
Represents a registered subcommand that will be auto-loaded.
Attributes
constant[R]
The fully qualified constant of the command class.
@return [String]
path[R]
The path to the file containing the command class.
@return [String]
summary[R]
A short summary for the sub-command.
@return [String, nil]
Public Class Methods
new(constant, path, summary: nil, **kwargs)
click to toggle source
Initializes the lazy-loaded subcommand.
@param [String] path
@param [String] constant
@param [String, nil] summary
A short summary for the subcommand.
@param [Hash{Symbol => Object}] kwargs
Keyword arguments.
@option kwargs [Array<String>] aliases
Optional alias names for the subcommand.
Calls superclass method
CommandKit::Commands::Subcommand::new
# File lib/command_kit/commands/auto_load/subcommand.rb, line 42 def initialize(constant, path, summary: nil, **kwargs) @constant = constant @path = path super(nil, summary: summary, **kwargs) end
Public Instance Methods
command()
click to toggle source
Lazy-loads the command class.
@return [Class]
The command class.
@raise [LoadError]
Could not load the given {#path}.
@raise [NameError]
Could not resolve the {#constant} for the command class.
# File lib/command_kit/commands/auto_load/subcommand.rb, line 83 def command @command ||= ( require! const_get ) end
const_get()
click to toggle source
Resolves the {#constant} for the command class.
@return [Class]
The command class.
@raise [NameError]
The command class could not be found.
# File lib/command_kit/commands/auto_load/subcommand.rb, line 67 def const_get Object.const_get("::#{@constant}",false) end
require!()
click to toggle source
Requires the file.
@return [Boolean]
# File lib/command_kit/commands/auto_load/subcommand.rb, line 54 def require! require(@path) end