posthog-ruby 3.29.0 → 3.29.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a3e8eecf2cef5e82e5cc8ba7f7ddefc8c9f372b86039c9e834ad6308b083a3e
4
- data.tar.gz: 7ea54f05eaf248de3f5106729d8f5d02c919b49c1e32db7030704288c8e6c8b2
3
+ metadata.gz: dc3cd53140f36b4f77fb11d60a903858d5053362e7c8fd3d8d4bd55472ed1c4a
4
+ data.tar.gz: f1213ce104a582ae6b9e82315538e31b77fc85dbe7336cdf0e41cbb169b0b47e
5
5
  SHA512:
6
- metadata.gz: 6a72a75666f8c77ab2aa9abfb863404ca9076de5f205da215f7fc24271999c75e144d8ded893d2e389218c0068383dfdcdbcbead6ce35e643947adc476a76602
7
- data.tar.gz: 6be683bbd6b6831913a146ac1cea6ac348c5dc929af6443131459febedf1e1890c32fb7b7482ba8f42402d7cdd1c9ebab7934b720be915bc432d376caa3389b7
6
+ metadata.gz: 489f3bd76d70c2034c62c02e217d6e09bd16e6600d9de7b757ae5bda1a0a24d7dafad88a735ddf13ab39fa18cffdab59fcb20e2d080689ff373238fce11f9925
7
+ data.tar.gz: ab7bb81da61fc82e4058355c95bc1d9b97018f0cbcfd5b476f380a058a39e9a0ce6ae3b8ce1fd11aa18acb4d4a1c4fb0cec3546f4729ee5a56dcf4e959e5ee3a
@@ -671,7 +671,7 @@ module PostHog
671
671
  )
672
672
  end
673
673
 
674
- person_properties, group_properties = add_local_person_and_group_properties(
674
+ groups, person_properties, group_properties = add_local_person_and_group_properties(
675
675
  groups, person_properties, group_properties
676
676
  )
677
677
 
@@ -806,8 +806,9 @@ module PostHog
806
806
  )
807
807
  return {} if @disabled
808
808
 
809
- person_properties, group_properties = add_local_person_and_group_properties(groups, person_properties,
810
- group_properties)
809
+ groups, person_properties, group_properties = add_local_person_and_group_properties(
810
+ groups, person_properties, group_properties
811
+ )
811
812
  @feature_flags_poller.get_all_flags(distinct_id, groups, person_properties, group_properties,
812
813
  only_evaluate_locally)
813
814
  end
@@ -846,8 +847,9 @@ module PostHog
846
847
  return nil if @disabled
847
848
 
848
849
  key = key.to_s
849
- person_properties, group_properties = add_local_person_and_group_properties(groups, person_properties,
850
- group_properties)
850
+ groups, person_properties, group_properties = add_local_person_and_group_properties(
851
+ groups, person_properties, group_properties
852
+ )
851
853
  @feature_flags_poller.get_feature_flag_payload(key, distinct_id, match_value, groups, person_properties,
852
854
  group_properties, only_evaluate_locally)
853
855
  end
@@ -873,7 +875,7 @@ module PostHog
873
875
  )
874
876
  return { featureFlags: {}, featureFlagPayloads: {} } if @disabled
875
877
 
876
- person_properties, group_properties = add_local_person_and_group_properties(
878
+ groups, person_properties, group_properties = add_local_person_and_group_properties(
877
879
  groups, person_properties, group_properties
878
880
  )
879
881
  response = @feature_flags_poller.get_all_flags_and_payloads(
@@ -1124,7 +1126,7 @@ module PostHog
1124
1126
  return nil if @disabled
1125
1127
 
1126
1128
  key = key.to_s
1127
- person_properties, group_properties = add_local_person_and_group_properties(
1129
+ groups, person_properties, group_properties = add_local_person_and_group_properties(
1128
1130
  groups, person_properties, group_properties
1129
1131
  )
1130
1132
  feature_flag_response, flag_was_locally_evaluated, request_id, evaluated_at, feature_flag_error, payload,
@@ -1290,17 +1292,9 @@ module PostHog
1290
1292
  end
1291
1293
 
1292
1294
  def add_local_person_and_group_properties(groups, person_properties, group_properties)
1293
- groups ||= {}
1294
- person_properties ||= {}
1295
- group_properties ||= {}
1296
-
1297
- symbolize_keys! groups
1298
- symbolize_keys! person_properties
1299
- symbolize_keys! group_properties
1300
-
1301
- group_properties.each_value do |value|
1302
- symbolize_keys! value
1303
- end
1295
+ groups, person_properties, group_properties = normalize_flag_evaluation_inputs(
1296
+ groups, person_properties, group_properties
1297
+ )
1304
1298
 
1305
1299
  all_group_properties = {}
1306
1300
  groups&.each do |group_name, group_key|
@@ -1309,7 +1303,7 @@ module PostHog
1309
1303
  }.merge((group_properties && group_properties[group_name]) || {})
1310
1304
  end
1311
1305
 
1312
- [person_properties, all_group_properties]
1306
+ [groups, person_properties, all_group_properties]
1313
1307
  end
1314
1308
  end
1315
1309
  end
@@ -150,6 +150,9 @@ module PostHog
150
150
  only_evaluate_locally = false,
151
151
  raise_on_error = false
152
152
  )
153
+ groups, person_properties, group_properties = normalize_flag_evaluation_inputs(
154
+ groups, person_properties, group_properties
155
+ )
153
156
  # TODO: Convert to options hash for easier argument passing
154
157
  flags_data = get_all_flags_and_payloads(
155
158
  distinct_id,
@@ -246,14 +249,6 @@ module PostHog
246
249
  load_feature_flags
247
250
  snapshot ||= _evaluation_snapshot
248
251
 
249
- symbolize_keys! groups
250
- symbolize_keys! person_properties
251
- symbolize_keys! group_properties
252
-
253
- group_properties.each_value do |value|
254
- symbolize_keys!(value)
255
- end
256
-
257
252
  response = nil
258
253
  payload = nil
259
254
  feature_flag = snapshot[:flags_by_key]&.[](key)
@@ -734,9 +729,6 @@ module PostHog
734
729
  def self.match_property(property, property_values, cohort_properties = {}, property_matching_version: 1)
735
730
  # only looks for matches where key exists in property_values
736
731
 
737
- PostHog::Utils.symbolize_keys! property
738
- PostHog::Utils.symbolize_keys! property_values
739
-
740
732
  # Handle cohort properties
741
733
  if extract_value(property, :type) == 'cohort'
742
734
  return match_cohort(property, property_values, cohort_properties,
@@ -753,25 +745,23 @@ module PostHog
753
745
  end
754
746
 
755
747
  def self.match_property_value(property, property_values, property_matching_version)
756
- key = property[:key].to_sym
757
- value = property[:value]
758
- operator = property[:operator] || 'exact'
759
-
760
- if !property_values.key?(key)
761
- raise InconclusiveMatchError.new("Property #{key} not found in property_values",
762
- reason: UnresolvedFlagReason::MISSING_CONTEXT)
763
- elsif operator == 'is_not_set'
764
- return false
748
+ key = (property[:key] || property['key']).to_sym
749
+ value = property.key?(:value) ? property[:value] : property['value']
750
+ operator = property[:operator] || property['operator'] || 'exact'
751
+ override_value = property_values.fetch(key) do
752
+ property_values.fetch(key.to_s) do
753
+ raise InconclusiveMatchError.new("Property #{key} not found in property_values",
754
+ reason: UnresolvedFlagReason::MISSING_CONTEXT)
755
+ end
765
756
  end
766
-
767
- override_value = property_values[key]
757
+ return false if operator == 'is_not_set'
768
758
 
769
759
  case operator
770
760
  when 'exact', 'is_not'
771
761
  matches = exact_property_match?(value, override_value, property_matching_version)
772
762
  operator == 'exact' ? matches : !matches
773
763
  when 'is_set'
774
- property_values.key?(key)
764
+ true
775
765
  when 'icontains'
776
766
  string_operand(override_value).downcase(:ascii).include?(value.to_s.downcase(:ascii))
777
767
  when 'not_icontains'
@@ -847,8 +837,9 @@ module PostHog
847
837
  # Raises an unsupported_definition error when local evaluation cannot use the filter, whatever
848
838
  # the call passes: an unknown operator, or a filter value that the operator cannot parse.
849
839
  def self.assert_filter_supported(property)
850
- value = property[:value]
851
- case property[:operator] || 'exact'
840
+ value = property.key?(:value) ? property[:value] : property['value']
841
+ operator = property[:operator] || property['operator'] || 'exact'
842
+ case operator
852
843
  when 'exact', 'is_not', 'is_set', 'is_not_set', 'icontains', 'not_icontains', 'starts_with',
853
844
  'not_starts_with', 'ends_with', 'not_ends_with'
854
845
  nil
@@ -871,7 +862,7 @@ module PostHog
871
862
  when 'semver_wildcard'
872
863
  semver_wildcard_bounds(value)
873
864
  else
874
- raise InconclusiveMatchError.new("Unknown operator: #{property[:operator]}",
865
+ raise InconclusiveMatchError.new("Unknown operator: #{operator}",
875
866
  reason: UnresolvedFlagReason::UNSUPPORTED_DEFINITION)
876
867
  end
877
868
  end
@@ -1086,10 +1077,9 @@ module PostHog
1086
1077
  end
1087
1078
  else
1088
1079
  property_group_items_match?(properties, group_type) do |prop|
1089
- PostHog::Utils.symbolize_keys!(prop)
1090
1080
  matches = match_property(prop, property_values, cohort_properties,
1091
1081
  property_matching_version: property_matching_version)
1092
- prop[:negation] ? !matches : matches
1082
+ extract_value(prop, :negation) ? !matches : matches
1093
1083
  end
1094
1084
  end
1095
1085
  end
data/lib/posthog/utils.rb CHANGED
@@ -21,6 +21,14 @@ module PostHog
21
21
  hash.replace symbolize_keys hash
22
22
  end
23
23
 
24
+ def normalize_flag_evaluation_inputs(groups, person_properties, group_properties)
25
+ [
26
+ symbolize_keys(groups || {}),
27
+ symbolize_keys(person_properties || {}),
28
+ symbolize_keys(group_properties || {}).transform_values { |properties| symbolize_keys(properties) }
29
+ ]
30
+ end
31
+
24
32
  # public: Return a new hash with keys as strings
25
33
  #
26
34
  def stringify_keys(hash)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.29.0'
4
+ VERSION = '3.29.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.29.0
4
+ version: 3.29.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''