Class: Ibex::Configuration::Value

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

Overview

A typed effective value plus the evidence needed to explain it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, origin:, declared_value: DECLARED_VALUE_UNSET) ⇒ Value

Returns a new instance of Value.

Raises:

  • (ArgumentError)


176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/ibex/configuration.rb', line 176

def initialize(key, value, origin:, declared_value: DECLARED_VALUE_UNSET)
  raise ArgumentError, "configuration value key must be a Configuration::Key" unless key.is_a?(Key)
  raise ArgumentError, "configuration value origin must be a Configuration::Origin" unless origin.is_a?(Origin)

  validate_provenance!(key, origin, declared_value)

  @key = key
  @value = key.validate(value)
  @origin = origin
  declared = declared_value #: config_value
  @declared_value = declared.equal?(DECLARED_VALUE_UNSET) ? nil : key.validate(declared)

  freeze
end

Instance Attribute Details

#declared_valueObject (readonly)

: config_value



172
173
174
# File 'lib/ibex/configuration.rb', line 172

def declared_value
  @declared_value
end

#keyObject (readonly)

: Key



169
170
171
# File 'lib/ibex/configuration.rb', line 169

def key
  @key
end

#originObject (readonly)

: Origin



171
172
173
# File 'lib/ibex/configuration.rb', line 171

def origin
  @origin
end

#valueObject (readonly)

: config_value



170
171
172
# File 'lib/ibex/configuration.rb', line 170

def value
  @value
end

Instance Method Details

#canonicalObject



220
221
222
# File 'lib/ibex/configuration.rb', line 220

def canonical
  @origin.kind != :analysis_override
end

#explicitObject

rubocop:disable Naming/PredicateMethod -- public JSON fields are named explicit/canonical.



215
216
217
# File 'lib/ibex/configuration.rb', line 215

def explicit
  @origin.kind != :builtin
end

#to_hObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ibex/configuration.rb', line 192

def to_h
  result = {
    "key" => @key.name,
    "value" => json_value(@value),
    "owner" => @key.owner_name,
    "policy" => @key.policy.to_s,
    "origin" => @origin.to_h,
    "explicit" => explicit,
    "canonical" => canonical
  } #: Hash[String, json_value]
  unless canonical
    result["analysis"] = {
      "declared" => json_value(@declared_value),
      "selected" => json_value(@value),
      "override" => true,
      "canonical_generation" => false
    }
  end
  result
end