Class: Ibex::Configuration::Report
- Inherits:
-
Object
- Object
- Ibex::Configuration::Report
- Defined in:
- lib/ibex/configuration/explanation.rb
Overview
Deterministic, static-no-user-code explanation of every registered setting.
Instance Attribute Summary collapse
-
#conflicts ⇒ Object
readonly
: Array.
-
#explanations ⇒ Object
readonly
: Array.
-
#input ⇒ Object
readonly
: Input.
Instance Method Summary collapse
-
#dump ⇒ Object
Deterministic JSON independent of caller hash insertion order.
-
#initialize(input, cli: {}) ⇒ Report
constructor
A new instance of Report.
- #render_text ⇒ Object
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(input, cli: {}) ⇒ Report
Returns a new instance of Report.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/ibex/configuration/explanation.rb', line 301 def initialize(input, cli: {}) raise ArgumentError, "configuration report input must be a Configuration::Input" unless input.is_a?(Input) cli.each_key { |name| Registry.fetch(name) } @input = input conflicts = [] #: Array[ConflictRecord] @explanations = Registry.keys.sort_by(&:name).map do |key| value = resolve_key(key, cli) explanation(value, cli) rescue Conflict => e record = ConflictRecord.new(e) conflicts << record explanation(e.declared, cli, conflict: record) end.freeze @conflicts = conflicts.freeze freeze end |
Instance Attribute Details
#conflicts ⇒ Object (readonly)
: Array
298 299 300 |
# File 'lib/ibex/configuration/explanation.rb', line 298 def conflicts @conflicts end |
#explanations ⇒ Object (readonly)
: Array
297 298 299 |
# File 'lib/ibex/configuration/explanation.rb', line 297 def explanations @explanations end |
#input ⇒ Object (readonly)
: Input
296 297 298 |
# File 'lib/ibex/configuration/explanation.rb', line 296 def input @input end |
Instance Method Details
#dump ⇒ Object
Deterministic JSON independent of caller hash insertion order.
340 341 342 |
# File 'lib/ibex/configuration/explanation.rb', line 340 def dump "#{JSON.generate(to_h)}\n" end |
#render_text ⇒ Object
345 346 347 348 349 350 |
# File 'lib/ibex/configuration/explanation.rb', line 345 def render_text lines = ["configuration status=#{success? ? 'ok' : 'conflict'} (static-no-user-code): #{@input.path}"] @explanations.each { |entry| lines.concat(render_explanation(entry)) } @conflicts.each { |conflict| lines << "conflict: #{conflict.}" } "#{lines.join("\n")}\n" end |
#success? ⇒ Boolean
321 322 323 |
# File 'lib/ibex/configuration/explanation.rb', line 321 def success? @conflicts.empty? end |
#to_h ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/ibex/configuration/explanation.rb', line 326 def to_h { "ibex_report" => "configuration", "schema_version" => 1, "trust" => "static-no-user-code", "status" => success? ? "ok" : "conflict", "input" => @input.to_h, "configuration" => @explanations.map(&:to_h), "conflicts" => @conflicts.map(&:to_h) } end |