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.
44 45 46 47 48 49 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 44 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.
16 17 18 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 16 def constant @constant end |
#path ⇒ String (readonly)
The path to the file containing the command class.
21 22 23 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 21 def path @path end |
#summary ⇒ String? (readonly)
A short summary for the sub-command.
26 27 28 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 26 def summary @summary end |
Instance Method Details
#command ⇒ Class
Lazy-loads the command class.
85 86 87 88 89 90 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 85 def command @command ||= ( require! const_get ) end |
#const_get ⇒ Class
Resolves the #constant for the command class.
69 70 71 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 69 def const_get Object.const_get("::#{@constant}",false) end |
#require! ⇒ Boolean
Requires the file.
56 57 58 |
# File 'lib/command_kit/commands/auto_load/subcommand.rb', line 56 def require! require(@path) end |