Class: Cabriolet::Commands::CommandDispatcher
- Inherits:
-
Object
- Object
- Cabriolet::Commands::CommandDispatcher
- Defined in:
- lib/cabriolet/cli/command_dispatcher.rb
Overview
Unified command dispatcher that routes commands to format-specific handlers
The dispatcher is responsible for:
-
Detecting the format of input files (or using manual override)
-
Selecting the appropriate format handler from the registry
-
Delegating command execution to the handler
This class implements the Strategy pattern, where the format handler is the strategy selected based on the detected format.
Class Method Summary collapse
-
.format_supported?(format) ⇒ Boolean
Check if a format is supported.
-
.supported_formats ⇒ Array<Symbol>
Get list of supported formats.
Instance Method Summary collapse
-
#dispatch(command, file, *args, **options) ⇒ void
Dispatch a command to the appropriate format handler.
-
#initialize(options = {}) ⇒ CommandDispatcher
constructor
Initialize the command dispatcher.
Constructor Details
#initialize(options = {}) ⇒ CommandDispatcher
Initialize the command dispatcher
29 30 31 32 |
# File 'lib/cabriolet/cli/command_dispatcher.rb', line 29 def initialize( = {}) @format_override = parse_format_option([:format]) @verbose = [:verbose] || false end |
Class Method Details
.format_supported?(format) ⇒ Boolean
Check if a format is supported
56 57 58 |
# File 'lib/cabriolet/cli/command_dispatcher.rb', line 56 def self.format_supported?(format) CommandRegistry.format_registered?(format) end |
.supported_formats ⇒ Array<Symbol>
Get list of supported formats
63 64 65 |
# File 'lib/cabriolet/cli/command_dispatcher.rb', line 63 def self.supported_formats CommandRegistry.registered_formats end |
Instance Method Details
#dispatch(command, file, *args, **options) ⇒ void
This method returns an undefined value.
Dispatch a command to the appropriate format handler
This method detects the format (if not manually specified), retrieves the appropriate handler, and delegates the command execution.
45 46 47 48 49 50 |
# File 'lib/cabriolet/cli/command_dispatcher.rb', line 45 def dispatch(command, file, *args, **) format = detect_format(file) handler = get_handler_for(format) execute_command(handler, command, file, args, ) end |