Class: Quonfig::EvalResult
- Inherits:
-
Object
- Object
- Quonfig::EvalResult
- Defined in:
- lib/quonfig/evaluator.rb
Overview
Result of a matched config evaluation. Provides the caller with both the raw JSON Value hash (#value) and a coerced Ruby value (#unwrapped_value). The test suite and integration helpers consume both shapes.
Constant Summary collapse
- REASON_UNKNOWN =
Integer reason codes for the api-telemetry EvalSummaries wire format. Match sdk-node/src/reason.ts.
0- REASON_STATIC =
1- REASON_TARGETING_MATCH =
2- REASON_SPLIT =
3
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#reportable_value ⇒ Object
readonly
Returns the value of attribute reportable_value.
-
#rule_index ⇒ Object
readonly
Returns the value of attribute rule_index.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#weighted_value_index ⇒ Object
Returns the value of attribute weighted_value_index.
Instance Method Summary collapse
-
#initialize(value:, rule_index:, config:, weighted_value_index: nil, reportable_value: nil) ⇒ EvalResult
constructor
A new instance of EvalResult.
-
#of_reason ⇒ Object
OpenFeature-aligned reason string.
-
#raw_value ⇒ Object
Raw underlying value without type coercion.
-
#type ⇒ Object
The declared Value type (‘string’, ‘int’, ‘bool’, …).
-
#unwrapped_value ⇒ Object
Ruby-native value after type coercion.
-
#value_type ⇒ Object
Convenience for callers that don’t care about coercion — mirrors the value shape sdk-node emits.
-
#wire_reason ⇒ Object
Integer reason code for telemetry.
Constructor Details
#initialize(value:, rule_index:, config:, weighted_value_index: nil, reportable_value: nil) ⇒ EvalResult
Returns a new instance of EvalResult.
422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/quonfig/evaluator.rb', line 422 def initialize(value:, rule_index:, config:, weighted_value_index: nil, reportable_value: nil) @value = value @rule_index = rule_index @config = config @weighted_value_index = weighted_value_index # Telemetry-safe substitute for #unwrapped_value. Set by Resolver when # the underlying Value was confidential / decryptWith, so callers # (the eval-summary aggregator) never see the plaintext. Mirrors # ReforgeHQ/sdk-ruby ConfigValueUnwrapper#reportable_value (the # `*****<5-md5>` hash form). @reportable_value = reportable_value end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
419 420 421 |
# File 'lib/quonfig/evaluator.rb', line 419 def config @config end |
#reportable_value ⇒ Object (readonly)
Returns the value of attribute reportable_value.
419 420 421 |
# File 'lib/quonfig/evaluator.rb', line 419 def reportable_value @reportable_value end |
#rule_index ⇒ Object (readonly)
Returns the value of attribute rule_index.
419 420 421 |
# File 'lib/quonfig/evaluator.rb', line 419 def rule_index @rule_index end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
419 420 421 |
# File 'lib/quonfig/evaluator.rb', line 419 def value @value end |
#weighted_value_index ⇒ Object
Returns the value of attribute weighted_value_index.
420 421 422 |
# File 'lib/quonfig/evaluator.rb', line 420 def weighted_value_index @weighted_value_index end |
Instance Method Details
#of_reason ⇒ Object
OpenFeature-aligned reason string. Same classification logic as wire_reason but as a public string the OF provider (and any third-party consumer of EvaluationDetails) can pass straight through.
Returns one of: “STATIC”, “TARGETING_MATCH”, “SPLIT”.
450 451 452 453 454 455 456 |
# File 'lib/quonfig/evaluator.rb', line 450 def of_reason case wire_reason when REASON_STATIC then EvaluationDetails::REASON_STATIC when REASON_SPLIT then EvaluationDetails::REASON_SPLIT else EvaluationDetails::REASON_TARGETING_MATCH end end |
#raw_value ⇒ Object
Raw underlying value without type coercion.
480 481 482 483 484 |
# File 'lib/quonfig/evaluator.rb', line 480 def raw_value return nil if @value.nil? @value[:value] || @value['value'] end |
#type ⇒ Object
The declared Value type (‘string’, ‘int’, ‘bool’, …). Nil if unset.
487 488 489 490 491 |
# File 'lib/quonfig/evaluator.rb', line 487 def type return nil if @value.nil? @value[:type] || @value['type'] end |
#unwrapped_value ⇒ Object
Ruby-native value after type coercion. Mirrors sdk-node Resolver#unwrapValue.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/quonfig/evaluator.rb', line 494 def unwrapped_value raw = raw_value case type when 'bool' then !!raw when 'int' return raw if raw.is_a?(Integer) return raw.to_i if raw.is_a?(Numeric) Integer(raw.to_s, 10) when 'double' return raw.to_f if raw.is_a?(Numeric) Float(raw.to_s) when 'string' then raw.to_s when 'string_list' then raw.is_a?(Array) ? raw.map(&:to_s) : [] when 'log_level' then raw.is_a?(Numeric) ? raw : raw.to_s when 'duration' then duration_to_millis(raw) when 'json' # JSON values must be native JS/Ruby types on the wire. raw else raw end end |
#value_type ⇒ Object
Convenience for callers that don’t care about coercion — mirrors the value shape sdk-node emits.
519 520 521 |
# File 'lib/quonfig/evaluator.rb', line 519 def value_type type end |
#wire_reason ⇒ Object
Integer reason code for telemetry. Mirrors sdk-node’s computeReason: SPLIT when a weighted variant is picked, STATIC when the first rule of a config with no targeting rules matched, otherwise TARGETING_MATCH.
438 439 440 441 442 443 |
# File 'lib/quonfig/evaluator.rb', line 438 def wire_reason return REASON_SPLIT unless @weighted_value_index.nil? return REASON_STATIC if @rule_index == 0 && !EvalResult.send(:targeting_rules?, @config) REASON_TARGETING_MATCH end |