@@ -24,10 +24,10 @@ def initialize(ufc_json)
2424 @parsed_config = parse_and_validate_json ( ufc_json )
2525 end
2626
27- def get_assignment ( _configuration , flag_key , _evaluation_context , expected_type , _time , default_value )
27+ def get_assignment ( flag_key , _evaluation_context , expected_type , _time , default_value )
2828 # Return default value if JSON parsing failed during initialization
29- if @parsed_config . is_a? ( ResolutionDetails )
30- return ResolutionDetails . new (
29+ if @parsed_config . is_a? ( EvaluationResult )
30+ return EvaluationResult . new (
3131 value : default_value ,
3232 error_code : @parsed_config . error_code ,
3333 error_message : @parsed_config . error_message
@@ -59,18 +59,18 @@ def get_assignment(_configuration, flag_key, _evaluation_context, expected_type,
5959 selected_allocation , selected_variation , reason = evaluate_flag_allocations ( flag , _evaluation_context , _time )
6060
6161 # Return the actual assignment result
62- ResolutionDetails . new (
62+ EvaluationResult . new (
6363 value : selected_variation . value ,
6464 reason : reason ,
6565 variant : selected_variation . key ,
6666 flag_metadata : {
6767 'allocationKey' => selected_allocation . key ,
6868 'doLog' => selected_allocation . do_log ,
69- 'variationType' => flag . variation_type
69+ 'variationType' => convert_variation_type_for_output ( flag . variation_type )
7070 }
7171 )
7272 rescue EvaluationError => e
73- # Convert evaluation errors to ResolutionDetails with default value - matches Rust error propagation
73+ # Convert evaluation errors to EvaluationResult with default value - matches Rust error propagation
7474 create_evaluation_error_with_default ( e . code , e . message , default_value )
7575 end
7676 end
@@ -110,23 +110,23 @@ def parse_and_validate_json(ufc_json)
110110 end
111111
112112 def create_parse_error ( error_code , error_message )
113- ResolutionDetails . new (
113+ EvaluationResult . new (
114114 value : nil ,
115115 error_code : error_code ,
116116 error_message : error_message
117117 )
118118 end
119119
120120 def create_evaluation_error ( error_code , error_message )
121- ResolutionDetails . new (
121+ EvaluationResult . new (
122122 value : nil ,
123123 error_code : error_code ,
124124 error_message : error_message
125125 )
126126 end
127127
128128 def create_evaluation_error_with_default ( error_code , error_message , default_value )
129- ResolutionDetails . new (
129+ EvaluationResult . new (
130130 value : default_value ,
131131 error_code : error_code ,
132132 error_message : error_message
@@ -255,11 +255,23 @@ def get_attribute_from_context(attribute_name, evaluation_context)
255255
256256 # If evaluation_context is a hash, look up the attribute
257257 if evaluation_context . respond_to? ( :[] )
258- evaluation_context [ attribute_name ] || evaluation_context [ attribute_name . to_sym ]
258+ attribute_value = evaluation_context [ attribute_name ] || evaluation_context [ attribute_name . to_sym ]
259+
260+ # Special handling for 'id' attribute: if not present, use targeting_key
261+ if attribute_value . nil? && attribute_name == 'id'
262+ attribute_value = get_targeting_key ( evaluation_context )
263+ end
264+
265+ attribute_value
259266 elsif evaluation_context . respond_to? ( attribute_name )
260267 evaluation_context . send ( attribute_name )
261268 else
262- nil
269+ # Special handling for 'id' attribute: if not present, use targeting_key
270+ if attribute_name == 'id'
271+ get_targeting_key ( evaluation_context )
272+ else
273+ nil
274+ end
263275 end
264276 end
265277
@@ -448,6 +460,19 @@ def determine_assignment_reason(allocation)
448460 AssignmentReason ::SPLIT
449461 end
450462 end
463+
464+ def convert_variation_type_for_output ( variation_type )
465+ # Convert from SCREAMING_SNAKE_CASE to lowercase format for output
466+ # This matches the expected test format
467+ case variation_type
468+ when VariationType ::STRING then 'string'
469+ when VariationType ::INTEGER then 'number'
470+ when VariationType ::NUMERIC then 'number'
471+ when VariationType ::BOOLEAN then 'boolean'
472+ when VariationType ::JSON then 'object'
473+ else variation_type # fallback to original value
474+ end
475+ end
451476 end
452477 end
453478 end
0 commit comments