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.
-
#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) ⇒ EvalResult
constructor
A new instance of EvalResult.
-
#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) ⇒ EvalResult
Returns a new instance of EvalResult.
422 423 424 425 426 427 |
# File 'lib/quonfig/evaluator.rb', line 422 def initialize(value:, rule_index:, config:, weighted_value_index: nil) @value = value @rule_index = rule_index @config = config @weighted_value_index = weighted_value_index 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 |
#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
#raw_value ⇒ Object
Raw underlying value without type coercion.
461 462 463 464 465 |
# File 'lib/quonfig/evaluator.rb', line 461 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.
468 469 470 471 472 |
# File 'lib/quonfig/evaluator.rb', line 468 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.
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/quonfig/evaluator.rb', line 475 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.
500 501 502 |
# File 'lib/quonfig/evaluator.rb', line 500 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.
432 433 434 435 436 437 |
# File 'lib/quonfig/evaluator.rb', line 432 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 |