Class: Canon::Options::Registry
- Inherits:
-
Object
- Object
- Canon::Options::Registry
- Defined in:
- lib/canon/options/registry.rb
Overview
Centralized registry for all Canon options This is the SINGLE SOURCE OF TRUTH for option definitions All interfaces (CLI, Ruby API, RSpec) auto-generate from this registry
Class Method Summary collapse
-
.all_options ⇒ Object
Get all option definitions.
-
.cli_flag_for(option_name) ⇒ Object
Get CLI flag name for an option.
-
.default_for(option_name, format = nil) ⇒ Object
Get default value for an option.
-
.options_for_format(format) ⇒ Object
Get options applicable to a specific format.
-
.validate_options!(opts, format) ⇒ Object
Validate options hash against registry.
Class Method Details
.all_options ⇒ Object
Get all option definitions
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/canon/options/registry.rb', line 13 def @all_options ||= [ preprocessing_option, diff_algorithm_option, diff_mode_option, *, match_profile_option, *, ].freeze end |
.cli_flag_for(option_name) ⇒ Object
Get CLI flag name for an option
42 43 44 45 |
# File 'lib/canon/options/registry.rb', line 42 def cli_flag_for(option_name) opt = .find { |o| o[:name] == option_name } opt&.dig(:cli_flag) end |
.default_for(option_name, format = nil) ⇒ Object
Get default value for an option
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/canon/options/registry.rb', line 48 def default_for(option_name, format = nil) opt = .find { |o| o[:name] == option_name } return nil unless opt # Check for format-specific default if format && opt[:format_defaults]&.key?(format) opt[:format_defaults][format] else opt[:default] end end |
.options_for_format(format) ⇒ Object
Get options applicable to a specific format
25 26 27 28 29 |
# File 'lib/canon/options/registry.rb', line 25 def (format) .select do |opt| opt[:applies_to].nil? || opt[:applies_to].include?(format) end end |
.validate_options!(opts, format) ⇒ Object
Validate options hash against registry
32 33 34 35 36 37 38 39 |
# File 'lib/canon/options/registry.rb', line 32 def (opts, format) valid_option_names = (format).map { |o| o[:name] } invalid = opts.keys - valid_option_names return if invalid.empty? raise Canon::Error, "Invalid options for #{format}: #{invalid.join(', ')}" end |