Class: Ibex::Configuration::Evidence
- Inherits:
-
Object
- Object
- Ibex::Configuration::Evidence
- 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 =
%i[accepted ignored duplicate conflicting].freeze
- SOURCES =
%i[grammar project cli].freeze
Instance Attribute Summary collapse
- #key ⇒ Key readonly
- #location ⇒ Location? readonly
- #reason ⇒ String readonly
- #source ⇒ Symbol readonly
- #status ⇒ Symbol readonly
- #value ⇒ config_value readonly
Instance Method Summary collapse
-
#initialize(key, source:, value:, status:, reason:, location: nil) ⇒ Evidence
constructor
A new instance of Evidence.
- #json_value(value) ⇒ String, ...
- #to_h ⇒ Hash[String, json_value]
Constructor Details
#initialize(key, source:, value:, status:, reason:, location: nil) ⇒ Evidence
Returns a new instance of Evidence.
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
#key ⇒ Key (readonly)
11 12 13 |
# File 'lib/ibex/configuration/explanation.rb', line 11 def key @key end |
#location ⇒ Location? (readonly)
15 16 17 |
# File 'lib/ibex/configuration/explanation.rb', line 15 def location @location end |
#reason ⇒ String (readonly)
16 17 18 |
# File 'lib/ibex/configuration/explanation.rb', line 16 def reason @reason end |
#source ⇒ Symbol (readonly)
12 13 14 |
# File 'lib/ibex/configuration/explanation.rb', line 12 def source @source end |
#status ⇒ Symbol (readonly)
14 15 16 |
# File 'lib/ibex/configuration/explanation.rb', line 14 def status @status end |
#value ⇒ config_value (readonly)
13 14 15 |
# File 'lib/ibex/configuration/explanation.rb', line 13 def value @value end |
Instance Method Details
#json_value(value) ⇒ String, ...
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_h ⇒ Hash[String, json_value]
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 |