Class: Ibex::Configuration::CLIAdapter
- Inherits:
-
Object
- Object
- Ibex::Configuration::CLIAdapter
- Defined in:
- lib/ibex/configuration.rb
Overview
Converts the existing internal CLI option hash into canonical concepts.
Instance Method Summary collapse
-
#configuration_values ⇒ Object
Canonical configuration values selected by explicit legacy CLI options.
-
#initialize(options, explicit_keys: options.keys) ⇒ CLIAdapter
constructor
The adapter receives the legacy CLI option map, which also contains operation flags and list values outside the closed configuration domain.
- #resolve(grammar: {}, locations: {}) ⇒ Object
Constructor Details
#initialize(options, explicit_keys: options.keys) ⇒ CLIAdapter
The adapter receives the legacy CLI option map, which also contains operation flags and list values outside the closed configuration domain. It validates and converts only declared configuration options.
531 532 533 534 535 536 |
# File 'lib/ibex/configuration.rb', line 531 def initialize(, explicit_keys: .keys) @options = .to_h do |name, value| [name, value.is_a?(String) ? value.dup.freeze : value] end.freeze @explicit_keys = explicit_keys.dup.freeze end |
Instance Method Details
#configuration_values ⇒ Object
Canonical configuration values selected by explicit legacy CLI options. Raw option spellings stop at this adapter boundary.
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/ibex/configuration.rb', line 548 def configuration_values = {} #: Hash[String, config_value] Registry::DEFINITIONS.each do |key| raw_name = key.cli_option next unless raw_name && @explicit_keys.include?(raw_name) && @options.key?(raw_name) [key.name] = if raw_name == :line_convert convert_line_mapping else convert(raw_name, @options.fetch(raw_name)) end end line_mapping = Registry.fetch("source.line_mapping") if !.key?(line_mapping.name) && @explicit_keys.include?(:line_convert_all) && @options.key?(:line_convert_all) [line_mapping.name] = convert_line_mapping end end |
#resolve(grammar: {}, locations: {}) ⇒ Object
539 540 541 542 543 |
# File 'lib/ibex/configuration.rb', line 539 def resolve(grammar: {}, locations: {}) source_locations = {} #: Hash[Symbol, Hash[String, Location]] source_locations[:grammar] = locations unless locations.empty? Resolver.new(grammar: grammar, cli: configuration_values, locations: source_locations) end |