Class: Cabriolet::Commands::CommandRegistry

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

Overview

Registry for mapping format symbols to command handler classes

This registry provides a centralized location for managing format handlers, following the Open/Closed Principle - new formats can be added without modifying existing command logic.

Examples:

Registering a format handler

CLI::CommandRegistry.register_format(:cab, CAB::CommandHandler)

Getting a handler for a format

handler = CLI::CommandRegistry.handler_for(:cab)

Class Method Summary collapse

Class Method Details

.clearvoid

This method returns an undefined value.

Clear all registered formats (primarily for testing)



60
61
62
# File 'lib/cabriolet/cli/command_registry.rb', line 60

def clear
  @handlers = {}
end

.format_registered?(format) ⇒ Boolean

Check if a format is registered

Parameters:

  • The format symbol

Returns:

  • true if the format has a registered handler



53
54
55
# File 'lib/cabriolet/cli/command_registry.rb', line 53

def format_registered?(format)
  @handlers.key?(format)
end

.handler_for(format) ⇒ Class?

Get the command handler class for a given format

Parameters:

  • The format symbol (e.g., :cab, :chm, :szdd)

Returns:

  • The handler class or nil if not registered



25
26
27
# File 'lib/cabriolet/cli/command_registry.rb', line 25

def handler_for(format)
  @handlers[format]
end

.register_format(format, handler_class) ⇒ Object

Register a command handler for a format

This allows for dynamic registration of format handlers, supporting extensibility and plugin architectures.

Parameters:

  • The format symbol

  • The command handler class

Raises:

  • if handler_class doesn’t implement required interface



37
38
39
40
# File 'lib/cabriolet/cli/command_registry.rb', line 37

def register_format(format, handler_class)
  validate_handler_interface(handler_class)
  @handlers[format] = handler_class
end

.registered_formatsArray<Symbol>

Get all registered formats

Returns:

  • List of registered format symbols



45
46
47
# File 'lib/cabriolet/cli/command_registry.rb', line 45

def registered_formats
  @handlers.keys
end