Class: Ibex::Configuration::Evidence

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

Overview

One observed configuration source and how it participated in selection.

Constant Summary collapse

STATUSES =

: Array

%i[accepted ignored duplicate conflicting].freeze
SOURCES =

: Array

%i[grammar project cli].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, source:, value:, status:, reason:, location: nil) ⇒ Evidence

Returns a new instance of Evidence.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ibex/configuration/explanation.rb', line 20

def initialize(key, source:, value:, status:, reason:, location: nil)
  raise ArgumentError, "configuration evidence key must be a Configuration::Key" unless key.is_a?(Key)
  raise ArgumentError, "unknown configuration evidence source: #{source.inspect}" unless SOURCES.include?(source)
  raise ArgumentError, "unknown configuration evidence status: #{status.inspect}" unless STATUSES.include?(status)
  unless location.nil? || location.is_a?(Location)
    raise ArgumentError, "configuration evidence location must be an Ibex::Location"
  end
  raise ArgumentError, "configuration evidence reason must not be empty" if reason.empty?

  @key = key
  @source = source
  @value = key.validate(value)
  @status = status
  @location = location
  @reason = reason.dup.freeze
  freeze
end

Instance Attribute Details

#keyObject (readonly)

: Key



11
12
13
# File 'lib/ibex/configuration/explanation.rb', line 11

def key
  @key
end

#locationObject (readonly)

: Location?



15
16
17
# File 'lib/ibex/configuration/explanation.rb', line 15

def location
  @location
end

#reasonObject (readonly)

: String



16
17
18
# File 'lib/ibex/configuration/explanation.rb', line 16

def reason
  @reason
end

#sourceObject (readonly)

: Symbol



12
13
14
# File 'lib/ibex/configuration/explanation.rb', line 12

def source
  @source
end

#statusObject (readonly)

: Symbol



14
15
16
# File 'lib/ibex/configuration/explanation.rb', line 14

def status
  @status
end

#valueObject (readonly)

: config_value



13
14
15
# File 'lib/ibex/configuration/explanation.rb', line 13

def value
  @value
end

Instance Method Details

#to_hObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ibex/configuration/explanation.rb', line 39

def to_h
  result = {
    "source" => @source.to_s,
    "value" => json_value(@value),
    "status" => @status.to_s,
    "reason" => @reason
  } #: Hash[String, json_value]
  location = @location
  result["location"] = location.to_h.transform_keys(&:to_s) if location
  result
end