Class: EpubTools::CLI::CommandRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/epub_tools/cli/command_registry.rb

Overview

Manages the registration and retrieval of commands

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandRegistry

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

#commandsObject (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_commandsArray<String>

Get all available command names

Returns:

  • (Array<String>)

    list of registered 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

Parameters:

  • name (String)

    the command name

Returns:

  • (Boolean)

    true if command exists



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

Parameters:

  • name (String)

    the command name

Returns:

  • (Hash, nil)

    the command configuration or nil if not found



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

Parameters:

  • name (String)

    the command name

  • command_class (Class)

    the class that implements the command

  • required_keys (Array<Symbol>) (defaults to: [])

    keys that must be present in options

  • default_options (Hash) (defaults to: {})

    default options for the command

Returns:

  • (self)


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 = [], default_options = {})
  @commands[name] = {
    class: command_class,
    required_keys: required_keys,
    default_options: default_options
  }
  self
end