posthog-ruby 3.37.0 → 3.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/posthog/feature_flags.rb +58 -5
- data/lib/posthog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7d45ebc25e56f929eac0c3ac3073efa2d39729aacd545d55ff35addc7678525c
|
|
4
|
+
data.tar.gz: a7a58e881539bd5e077502da679b475a7a57701d9864aa3a793e89fb15c84e72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8194864f84a8339a1040e54828ff0784527a932782cae1a2b3896a73fdc2b65029641143a3b56e8860e746506c3286c2c261034dbc72d7b3bb1bf73541c1b9d8
|
|
7
|
+
data.tar.gz: 53ac837ed109538c76b6165d403034d4f5bc3884c52865efdb98ebcbc5e69794ebb5c0b993338b9e5f697ac8167aa3086fd3734b5417fca6eb713082dd910af3
|
|
@@ -779,7 +779,9 @@ module PostHog
|
|
|
779
779
|
end
|
|
780
780
|
|
|
781
781
|
def self.match_property_value(property, property_values, property_matching_version)
|
|
782
|
-
key =
|
|
782
|
+
key = property[:key] || property['key']
|
|
783
|
+
key = key.to_s if key.is_a?(Numeric)
|
|
784
|
+
key = key.to_sym
|
|
783
785
|
value = property.key?(:value) ? property[:value] : property['value']
|
|
784
786
|
operator = property[:operator] || property['operator'] || 'exact'
|
|
785
787
|
override_value = property_values.fetch(key) do
|
|
@@ -1111,6 +1113,7 @@ module PostHog
|
|
|
1111
1113
|
)
|
|
1112
1114
|
end
|
|
1113
1115
|
|
|
1116
|
+
assert_cohort_flag_leaves_parse(property_group, cohort_properties, Set.new)
|
|
1114
1117
|
match_property_group(property_group, property_values, cohort_properties,
|
|
1115
1118
|
property_matching_version: property_matching_version)
|
|
1116
1119
|
end
|
|
@@ -1130,13 +1133,57 @@ module PostHog
|
|
|
1130
1133
|
end
|
|
1131
1134
|
else
|
|
1132
1135
|
property_group_items_match?(properties, group_type) do |prop|
|
|
1133
|
-
matches =
|
|
1134
|
-
|
|
1136
|
+
matches = if cohort_flag_dependency?(prop)
|
|
1137
|
+
false
|
|
1138
|
+
else
|
|
1139
|
+
match_property(prop, property_values, cohort_properties,
|
|
1140
|
+
property_matching_version: property_matching_version)
|
|
1141
|
+
end
|
|
1135
1142
|
extract_value(prop, :negation) ? !matches : matches
|
|
1136
1143
|
end
|
|
1137
1144
|
end
|
|
1138
1145
|
end
|
|
1139
1146
|
|
|
1147
|
+
# The flags service doesn't resolve a flag dependency inside a cohort. Its property matcher
|
|
1148
|
+
# rejects flag_evaluates_to, which makes the leaf a definitive non-match.
|
|
1149
|
+
def self.cohort_flag_dependency?(property)
|
|
1150
|
+
extract_value(property, :type) == 'flag' && extract_value(property, :operator) == 'flag_evaluates_to'
|
|
1151
|
+
end
|
|
1152
|
+
|
|
1153
|
+
def self.unparsable_cohort_flag_leaf?(property)
|
|
1154
|
+
return false unless extract_value(property, :type) == 'flag'
|
|
1155
|
+
|
|
1156
|
+
key = extract_value(property, :key)
|
|
1157
|
+
!(key.is_a?(String) || key.is_a?(Numeric))
|
|
1158
|
+
end
|
|
1159
|
+
|
|
1160
|
+
# The flags service parses every leaf of a cohort and of the cohorts it references before it
|
|
1161
|
+
# evaluates any of them, so a flag leaf without a string or numeric key fails the cohort even when
|
|
1162
|
+
# another leaf would decide it. It skips groups of a type it can't evaluate.
|
|
1163
|
+
# RequiresServerEvaluation isn't an InconclusiveMatchError, so no group swallows it.
|
|
1164
|
+
def self.assert_cohort_flag_leaves_parse(property_group, cohort_properties, visited_cohort_ids)
|
|
1165
|
+
return unless %w[AND OR].include?(extract_value(property_group, :type))
|
|
1166
|
+
|
|
1167
|
+
(extract_value(property_group, :values) || []).each do |item|
|
|
1168
|
+
next unless item.is_a?(Hash)
|
|
1169
|
+
|
|
1170
|
+
if item.key?(:values) || item.key?('values')
|
|
1171
|
+
assert_cohort_flag_leaves_parse(item, cohort_properties, visited_cohort_ids)
|
|
1172
|
+
elsif extract_value(item, :type) == 'cohort'
|
|
1173
|
+
cohort_id = extract_value(item, :value).to_s
|
|
1174
|
+
referenced = find_cohort_property(cohort_properties, cohort_id)
|
|
1175
|
+
next if referenced.nil? || !visited_cohort_ids.add?(cohort_id)
|
|
1176
|
+
|
|
1177
|
+
assert_cohort_flag_leaves_parse(referenced, cohort_properties, visited_cohort_ids)
|
|
1178
|
+
elsif unparsable_cohort_flag_leaf?(item)
|
|
1179
|
+
raise RequiresServerEvaluation.new(
|
|
1180
|
+
"Can't parse a cohort flag filter with key #{extract_value(item, :key).inspect}",
|
|
1181
|
+
reason: UnresolvedFlagReason::UNSUPPORTED_DEFINITION
|
|
1182
|
+
)
|
|
1183
|
+
end
|
|
1184
|
+
end
|
|
1185
|
+
end
|
|
1186
|
+
|
|
1140
1187
|
def self.extract_value(hash, key)
|
|
1141
1188
|
return nil unless hash.is_a?(Hash)
|
|
1142
1189
|
|
|
@@ -1379,8 +1426,12 @@ module PostHog
|
|
|
1379
1426
|
filter = PostHog::Utils.symbolize_keys(property)
|
|
1380
1427
|
if filter[:type] == 'cohort'
|
|
1381
1428
|
unsupported_property?(filter, flags_by_key, cohorts, visited_cohort_ids)
|
|
1429
|
+
elsif unparsable_cohort_flag_leaf?(filter)
|
|
1430
|
+
true
|
|
1431
|
+
elsif cohort_flag_dependency?(filter)
|
|
1432
|
+
false
|
|
1382
1433
|
else
|
|
1383
|
-
# Like evaluation, a cohort group checks
|
|
1434
|
+
# Like evaluation, a cohort group checks any other flag filter as an ordinary property.
|
|
1384
1435
|
unsupported_filter?(filter)
|
|
1385
1436
|
end
|
|
1386
1437
|
end
|
|
@@ -1394,7 +1445,9 @@ module PostHog
|
|
|
1394
1445
|
true
|
|
1395
1446
|
end
|
|
1396
1447
|
|
|
1397
|
-
private_class_method :extract_value, :
|
|
1448
|
+
private_class_method :extract_value, :cohort_flag_dependency?, :unparsable_cohort_flag_leaf?,
|
|
1449
|
+
:assert_cohort_flag_leaves_parse,
|
|
1450
|
+
:find_cohort_property, :nested_property_group?,
|
|
1398
1451
|
:property_group_items_match?, :assert_property_filter_type_supported,
|
|
1399
1452
|
:assert_filter_supported,
|
|
1400
1453
|
:unsupported_property?, :unsupported_property_group?, :unsupported_filter?
|
data/lib/posthog/version.rb
CHANGED