Class: Ibex::Configuration::Resolver

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

Overview

Applies fixed/minimum override algebra and exposes deterministic evidence.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys: Registry.keys, grammar: {}, project: {}, cli: {}, analysis_overrides: {}, locations: {}) ⇒ Resolver

Returns a new instance of Resolver.

Raises:

  • (ArgumentError)


366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/ibex/configuration.rb', line 366

def initialize(keys: Registry.keys, grammar: {}, project: {}, cli: {}, analysis_overrides: {}, locations: {})
  @keys = keys.sort_by(&:name).freeze
  @key_index = @keys.to_h { |key| [key.name, key] }.freeze
  raise ArgumentError, "duplicate configuration key definition" unless @key_index.length == @keys.length

  sources = { grammar: grammar, project: project, cli: cli, analysis_override: analysis_overrides }
  sources.each { |kind, entries| validate_source!(kind, entries) }
  validate_locations!(locations, sources)
  @values = @keys.map do |key|
    resolve_key(key, sources, locations)
  end.freeze
  @value_index = @values.to_h { |entry| [entry.key.name, entry] }.freeze
  freeze
end

Instance Attribute Details

#valuesObject (readonly)

: Array



361
362
363
# File 'lib/ibex/configuration.rb', line 361

def values
  @values
end

Instance Method Details

#dumpObject

Deterministic JSON independent of caller hash insertion order.



398
399
400
# File 'lib/ibex/configuration.rb', line 398

def dump
  "#{JSON.generate(to_h)}\n"
end

#fetch(name) ⇒ Object



382
383
384
# File 'lib/ibex/configuration.rb', line 382

def fetch(name)
  @value_index.fetch(name) { raise ArgumentError, "unknown configuration key: #{name.inspect}" }
end

#to_hObject



392
393
394
# File 'lib/ibex/configuration.rb', line 392

def to_h
  { "configuration" => @values.map(&:to_h) }
end

#value(name) ⇒ Object



387
388
389
# File 'lib/ibex/configuration.rb', line 387

def value(name)
  fetch(name).value
end