Class: CommandKit::Commands::AutoLoad::Subcommand
- Inherits:
-
Subcommand
- Object
- Subcommand
- CommandKit::Commands::AutoLoad::Subcommand
- Defined in:
- lib/command_kit/commands/auto_load/subcommand.rb
Overview
Represents a registered subcommand that will be auto-loaded.
Instance Attribute Summary collapse
-
#constant ⇒ String
readonly
The fully qualified constant of the command class.
-
#path ⇒ String
readonly
The path to the file containing the command class.
-
#summary ⇒ String?
readonly
A short summary for the sub-command.
Attributes inherited from Subcommand
Instance Method Summary collapse
-
#command ⇒ Class
Lazy-loads the command class.
-
#const_get ⇒ Class
Resolves the #constant for the command class.
-
#initialize(constant, path, summary: nil, **kwargs) ⇒ Subcommand
constructor
Initializes the lazy-loaded subcommand.
-
#require! ⇒ Boolean
Requires the file.
Methods inherited from Subcommand
Constructor Details
#initialize(constant, path, summary: nil, **kwargs) ⇒ Subcommand
Initializes the lazy-loaded subcommand.
42 43 44 45 46 47 |
# 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 |
Instance Attribute Details
#constant ⇒ String (readonly)
The fully qualified constant of the command class.
14 15 16 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 14 def constant @constant end |
#path ⇒ String (readonly)
The path to the file containing the command class.
19 20 21 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 19 def path @path end |
#summary ⇒ String? (readonly)
A short summary for the sub-command.
24 25 26 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 24 def summary @summary end |
Instance Method Details
#command ⇒ Class
Lazy-loads the command class.
83 84 85 86 87 88 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 83 def command @command ||= ( require! const_get ) end |
#const_get ⇒ Class
Resolves the #constant for the command class.
67 68 69 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 67 def const_get Object.const_get("::#{@constant}",false) end |
#require! ⇒ Boolean
Requires the file.
54 55 56 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 54 def require! require(@path) end |