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.
430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/quonfig/evaluator.rb', line 430 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.
427 428 429 |
# File 'lib/quonfig/evaluator.rb', line 427 def config @config end |
#reportable_value ⇒ Object (readonly)
Returns the value of attribute reportable_value.
427 428 429 |
# File 'lib/quonfig/evaluator.rb', line 427 def reportable_value @reportable_value end |
#rule_index ⇒ Object (readonly)
Returns the value of attribute rule_index.
427 428 429 |
# File 'lib/quonfig/evaluator.rb', line 427 def rule_index @rule_index end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
427 428 429 |
# File 'lib/quonfig/evaluator.rb', line 427 def value @value end |
#weighted_value_index ⇒ Object
Returns the value of attribute weighted_value_index.
428 429 430 |
# File 'lib/quonfig/evaluator.rb', line 428 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”.
458 459 460 461 462 463 464 |
# File 'lib/quonfig/evaluator.rb', line 458 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.
488 489 490 491 492 |
# File 'lib/quonfig/evaluator.rb', line 488 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.
495 496 497 498 499 |
# File 'lib/quonfig/evaluator.rb', line 495 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.
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/quonfig/evaluator.rb', line 502 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.
529 530 531 |
# File 'lib/quonfig/evaluator.rb', line 529 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.
446 447 448 449 450 451 |
# File 'lib/quonfig/evaluator.rb', line 446 def wire_reason return REASON_SPLIT unless @weighted_value_index.nil? return REASON_STATIC if @rule_index.zero? && !EvalResult.send(:targeting_rules?, @config) REASON_TARGETING_MATCH end |