Class: Ibex::Configuration::CLIAdapter

Inherits:
Object
  • Object
show all
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

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.

RBS:

  • (Hash[Symbol, untyped] options, ?explicit_keys: Array[Symbol]) -> void

Parameters:

  • options (Hash[Symbol, untyped])
  • explicit_keys: (Array[Symbol]) (defaults to: options.keys)


502
503
504
505
506
507
# File 'lib/ibex/configuration.rb', line 502

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_valuesHash[String, config_value]

Canonical configuration values selected by explicit legacy CLI options. Raw option spellings stop at this adapter boundary.

RBS:

  • () -> Hash[String, config_value]

Returns:

  • (Hash[String, config_value])


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
  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

#convert(name, value) ⇒ config_value

RBS:

  • (Symbol name, untyped value) -> config_value

Parameters:

  • name (Symbol)
  • value (Object)

Returns:

  • (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

RBS:

  • (untyped value) -> config_value

Parameters:

  • value (Object)

Returns:

  • (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_mappingSymbol

RBS:

  • () -> Symbol

Returns:

  • (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

RBS:

  • (?grammar: Hash[String, config_value], ?locations: Hash[String, Location]) -> Resolver

Parameters:

  • grammar: (Hash[String, config_value]) (defaults to: {})
  • locations: (Hash[String, Location]) (defaults to: {})

Returns:



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