@@ -14,7 +14,7 @@ module Evaluator # rubocop:disable Metrics/ModuleLength
1414 include Flagsmith ::Engine ::Segments ::Constants
1515 include Flagsmith ::Engine ::Utils ::HashFunc
1616
17- # Model-based segment evaluation (existing approach)
17+ # Model-based segment evaluation
1818 def get_identity_segments ( environment , identity , override_traits = nil )
1919 environment . project . segments . select do |s |
2020 evaluate_identity_in_segment ( identity , s , override_traits )
@@ -39,7 +39,19 @@ def traits_match_segment_condition(identity_traits, condition, segment_id, ident
3939
4040 module_function
4141
42- # Context-based segment evaluation (new approach)
42+ def get_enriched_context ( context )
43+ identity_context = context [ :identity ]
44+ return context unless identity_context
45+ return context if identity_context [ :key ]
46+
47+ enriched_context = context . dup
48+ enriched_context [ :identity ] = identity_context . merge (
49+ key : "#{ context [ :environment ] [ :key ] } _#{ identity_context [ :identifier ] } "
50+ )
51+ enriched_context
52+ end
53+
54+ # Context-based segment evaluation
4355 # Returns all segments that the identity belongs to based on segment rules evaluation
4456 #
4557 # @param context [Hash] Evaluation context containing identity and segment definitions
@@ -92,7 +104,7 @@ def traits_match_segment_rule(identity_traits, rule, segment_id, identity_id)
92104 end
93105 # rubocop:enable Metrics/MethodLength
94106
95- # Context-based helper functions (new approach)
107+ # Context-based helper functions
96108
97109 # Evaluates whether a segment rule matches using context
98110 #
@@ -224,8 +236,7 @@ def get_context_value(json_path, context)
224236 def get_identity_key_from_context ( context )
225237 return nil unless context [ :identity ]
226238
227- context [ :identity ] [ :key ] ||
228- "#{ context [ :environment ] [ :key ] } _#{ context [ :identity ] [ :identifier ] } "
239+ context [ :identity ] [ :key ]
229240 end
230241
231242 # Check if value is primitive (not an object or array)
0 commit comments