Class: Ibex::Configuration::CLIAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/configuration.rb

Overview

Converts the existing internal CLI option hash into canonical concepts.

Instance Method Summary collapse

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(options, explicit_keys: options.keys)
  @options = 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_valuesObject

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
  options = {} #: 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)

    options[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 !options.key?(line_mapping.name) && @explicit_keys.include?(:line_convert_all) &&
     @options.key?(:line_convert_all)
    options[line_mapping.name] = convert_line_mapping
  end
  options
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