Class: EpubTools::CLI::CommandRegistry
- Inherits:
-
Object
- Object
- EpubTools::CLI::CommandRegistry
- Defined in:
- lib/epub_tools/cli/command_registry.rb
Overview
Manages the registration and retrieval of commands
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
-
#available_commands ⇒ Array<String>
Get all available command names.
-
#command_exists?(name) ⇒ Boolean
Check if a command is registered.
-
#get(name) ⇒ Hash?
Get a command by name.
-
#initialize ⇒ CommandRegistry
constructor
A new instance of CommandRegistry.
-
#register(name, command_class, required_keys = [], default_options = {}) ⇒ self
Register a new command in the registry.
Constructor Details
#initialize ⇒ CommandRegistry
Returns a new instance of CommandRegistry.
7 8 9 |
# File 'lib/epub_tools/cli/command_registry.rb', line 7 def initialize @commands = {} end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
5 6 7 |
# File 'lib/epub_tools/cli/command_registry.rb', line 5 def commands @commands end |
Instance Method Details
#available_commands ⇒ Array<String>
Get all available command names
35 36 37 |
# File 'lib/epub_tools/cli/command_registry.rb', line 35 def available_commands @commands.keys end |
#command_exists?(name) ⇒ Boolean
Check if a command is registered
42 43 44 |
# File 'lib/epub_tools/cli/command_registry.rb', line 42 def command_exists?(name) @commands.key?(name) end |
#get(name) ⇒ Hash?
Get a command by name
29 30 31 |
# File 'lib/epub_tools/cli/command_registry.rb', line 29 def get(name) @commands[name] end |
#register(name, command_class, required_keys = [], default_options = {}) ⇒ self
Register a new command in the registry
17 18 19 20 21 22 23 24 |
# File 'lib/epub_tools/cli/command_registry.rb', line 17 def register(name, command_class, required_keys = [], = {}) @commands[name] = { class: command_class, required_keys: required_keys, default_options: } self end |