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.
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.
Instance Method Summary collapse
-
#initialize(value:, rule_index:, config:) ⇒ 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.
Constructor Details
#initialize(value:, rule_index:, config:) ⇒ EvalResult
Returns a new instance of EvalResult.
414 415 416 417 418 |
# File 'lib/quonfig/evaluator.rb', line 414 def initialize(value:, rule_index:, config:) @value = value @rule_index = rule_index @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
412 413 414 |
# File 'lib/quonfig/evaluator.rb', line 412 def config @config end |
#rule_index ⇒ Object (readonly)
Returns the value of attribute rule_index.
412 413 414 |
# File 'lib/quonfig/evaluator.rb', line 412 def rule_index @rule_index end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
412 413 414 |
# File 'lib/quonfig/evaluator.rb', line 412 def value @value end |
Instance Method Details
#raw_value ⇒ Object
Raw underlying value without type coercion.
421 422 423 424 425 |
# File 'lib/quonfig/evaluator.rb', line 421 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.
428 429 430 431 432 |
# File 'lib/quonfig/evaluator.rb', line 428 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.
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/quonfig/evaluator.rb', line 435 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 raw.to_s 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.
460 461 462 |
# File 'lib/quonfig/evaluator.rb', line 460 def value_type type end |