Class: Ibex::Configuration::Value
- Inherits:
-
Object
- Object
- Ibex::Configuration::Value
- Defined in:
- lib/ibex/configuration.rb
Overview
A typed effective value plus the evidence needed to explain it.
Instance Attribute Summary collapse
-
#declared_value ⇒ Object
readonly
: config_value.
-
#key ⇒ Object
readonly
: Key.
-
#origin ⇒ Object
readonly
: Origin.
-
#value ⇒ Object
readonly
: config_value.
Instance Method Summary collapse
- #canonical ⇒ Object
-
#explicit ⇒ Object
rubocop:disable Naming/PredicateMethod -- public JSON fields are named explicit/canonical.
-
#initialize(key, value, origin:, declared_value: DECLARED_VALUE_UNSET) ⇒ Value
constructor
A new instance of Value.
- #to_h ⇒ Object
Constructor Details
#initialize(key, value, origin:, declared_value: DECLARED_VALUE_UNSET) ⇒ Value
Returns a new instance of Value.
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_value ⇒ Object (readonly)
: config_value
172 173 174 |
# File 'lib/ibex/configuration.rb', line 172 def declared_value @declared_value end |
#key ⇒ Object (readonly)
: Key
169 170 171 |
# File 'lib/ibex/configuration.rb', line 169 def key @key end |
#origin ⇒ Object (readonly)
: Origin
171 172 173 |
# File 'lib/ibex/configuration.rb', line 171 def origin @origin end |
#value ⇒ Object (readonly)
: config_value
170 171 172 |
# File 'lib/ibex/configuration.rb', line 170 def value @value end |
Instance Method Details
#canonical ⇒ Object
220 221 222 |
# File 'lib/ibex/configuration.rb', line 220 def canonical @origin.kind != :analysis_override end |
#explicit ⇒ Object
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_h ⇒ Object
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 |