Class: Ibex::Configuration::CLIAdapter
- Inherits:
-
Object
- Object
- Ibex::Configuration::CLIAdapter
- Defined in:
- lib/ibex/configuration.rb,
sig/ibex/configuration.rbs
Overview
Converts the existing internal CLI option hash into canonical concepts.
Instance Method Summary collapse
-
#configuration_values ⇒ Hash[String, config_value]
Canonical configuration values selected by explicit legacy CLI options.
- #convert(name, value) ⇒ config_value
- #convert_entry_isolation(value) ⇒ config_value
- #convert_line_mapping ⇒ Symbol
-
#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: {}) ⇒ Resolver
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.
502 503 504 505 506 507 |
# File 'lib/ibex/configuration.rb', line 502 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 ⇒ Hash[String, config_value]
Canonical configuration values selected by explicit legacy CLI options. Raw option spellings stop at this adapter boundary.
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/ibex/configuration.rb', line 519 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 |
#convert(name, value) ⇒ config_value
542 543 544 545 546 547 548 |
# File 'lib/ibex/configuration.rb', line 542 def convert(name, value) case name when :entry_isolation then convert_entry_isolation(value) when :cst_trivia then value == :attach ? :leading : value else value end end |
#convert_entry_isolation(value) ⇒ config_value
551 552 553 554 555 556 |
# File 'lib/ibex/configuration.rb', line 551 def convert_entry_isolation(value) return :isolated if value == true return :shared if value == false value end |
#convert_line_mapping ⇒ Symbol
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/ibex/configuration.rb', line 559 def convert_line_mapping line_convert = @options.fetch(:line_convert, true) line_convert_all = @options.fetch(:line_convert_all, false) unless BOOLEAN_VALUES.include?(line_convert) raise ArgumentError, "line_convert expects boolean, got #{line_convert.inspect}" end unless BOOLEAN_VALUES.include?(line_convert_all) raise ArgumentError, "line_convert_all expects boolean, got #{line_convert_all.inspect}" end if line_convert_all && !line_convert raise ArgumentError, "line_convert_all=true conflicts with line_convert=false" end return :all if line_convert_all return :none unless line_convert :actions end |
#resolve(grammar: {}, locations: {}) ⇒ Resolver
510 511 512 513 514 |
# File 'lib/ibex/configuration.rb', line 510 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 |