@@ -13,6 +13,31 @@ module Segments
1313 module Evaluator
1414 include Flagsmith ::Engine ::Segments ::Constants
1515 include Flagsmith ::Engine ::Utils ::HashFunc
16+
17+ # Model-based segment evaluation (existing approach)
18+ def get_identity_segments ( environment , identity , override_traits = nil )
19+ environment . project . segments . select do |s |
20+ evaluate_identity_in_segment ( identity , s , override_traits )
21+ end
22+ end
23+
24+
25+ def traits_match_segment_condition ( identity_traits , condition , segment_id , identity_id )
26+ if condition . operator == PERCENTAGE_SPLIT
27+ return hashed_percentage_for_object_ids ( [ segment_id ,
28+ identity_id ] ) <= condition . value . to_f
29+ end
30+
31+ trait = identity_traits . find { |t | t . key . to_s == condition . property }
32+
33+ return handle_trait_existence_conditions ( trait , condition . operator ) if [ IS_SET ,
34+ IS_NOT_SET ] . include? ( condition . operator )
35+
36+ return condition . match_trait_value? ( trait . trait_value ) if trait
37+
38+ false
39+ end
40+
1641
1742 module_function
1843 # Context-based segment evaluation (new approach)
@@ -31,13 +56,6 @@ def get_identity_segments_from_context(context)
3156 end
3257 end
3358
34- # Model-based segment evaluation (existing approach)
35- def get_identity_segments ( environment , identity , override_traits = nil )
36- environment . project . segments . select do |s |
37- evaluate_identity_in_segment ( identity , s , override_traits )
38- end
39- end
40-
4159 # Evaluates whether a given identity is in the provided segment.
4260 #
4361 # :param identity: identity model object to evaluate
@@ -75,22 +93,6 @@ def traits_match_segment_rule(identity_traits, rule, segment_id, identity_id)
7593 end
7694 # rubocop:enable Metrics/MethodLength
7795
78- def traits_match_segment_condition ( identity_traits , condition , segment_id , identity_id )
79- if condition . operator == PERCENTAGE_SPLIT
80- return hashed_percentage_for_object_ids ( [ segment_id ,
81- identity_id ] ) <= condition . value . to_f
82- end
83-
84- trait = identity_traits . find { |t | t . key . to_s == condition . property }
85-
86- return handle_trait_existence_conditions ( trait , condition . operator ) if [ IS_SET ,
87- IS_NOT_SET ] . include? ( condition . operator )
88-
89- return condition . match_trait_value? ( trait . trait_value ) if trait
90-
91- false
92- end
93-
9496 # Context-based helper functions (new approach)
9597
9698 # Evaluates whether a segment rule matches using context
0 commit comments