Class: Ibex::Configuration::Evidence

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

Overview

One observed configuration source and how it participated in selection.

Constant Summary collapse

STATUSES =

Signature:

  • Array[Symbol]

Returns:

  • (Array[Symbol])
%i[accepted ignored duplicate conflicting].freeze
SOURCES =

Signature:

  • Array[Symbol]

Returns:

  • (Array[Symbol])
%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.

RBS:

  • (Key key, source: Symbol, value: config_value, status: Symbol, reason: String, ?location: Location?) -> void

Parameters:

  • key (Key)
  • source: (Symbol)
  • value: (config_value)
  • status: (Symbol)
  • reason: (String)
  • location: (Location, nil) (defaults to: nil)


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

#keyKey (readonly)

Signature:

  • Key

Returns:



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

def key
  @key
end

#locationLocation? (readonly)

Signature:

  • Location?

Returns:



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

def location
  @location
end

#reasonString (readonly)

Signature:

  • String

Returns:

  • (String)


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

def reason
  @reason
end

#sourceSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


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

def source
  @source
end

#statusSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


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

def status
  @status
end

#valueconfig_value (readonly)

Signature:

  • config_value

Returns:

  • (config_value)


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

def value
  @value
end

Instance Method Details

#json_value(value) ⇒ String, ...

RBS:

  • (config_value value) -> (String | Integer | bool | nil)

Parameters:

  • value (config_value)

Returns:

  • (String, Integer, bool, nil)


54
55
56
# File 'lib/ibex/configuration/explanation.rb', line 54

def json_value(value)
  value.is_a?(Symbol) ? value.to_s : value
end

#to_hHash[String, json_value]

RBS:

  • () -> Hash[String, json_value]

Returns:



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