posthog-ruby 3.27.1 → 3.28.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: 125a7a9c4063477324ed9654c1035ff28e959cb6c389dfbcfc5ee08bb17153ab
4
- data.tar.gz: b02e50631f58cb0e119184c1556766c55ee0e1ae578514620b6217a916207b7e
3
+ metadata.gz: 8c845018be0215ef9e7b28c605f4ed856815d4eb63076c2b76aa307a04fa5a47
4
+ data.tar.gz: 9e0779372eea8be6e073c3d200159f7f1ac31986b3390147987368935f4710f4
5
5
  SHA512:
6
- metadata.gz: 1adee637ab5766731429e73e4bd41b102c9bb33fc285b75b4a62dd173a6fa0c4825ee47ff87b007d8cc8c517c8eab6103b33337b62fd4504497c2c127580c7c2
7
- data.tar.gz: 82c8accf93eede6fe7c4748967377b7fa9a1ffc28f7c9ed85e6355ba81d2312962767488436af285c57e0bfc9ebcd442dd486157644b708e9dbd03ad045fd712
6
+ metadata.gz: 74eff3ba167884c7059a1dfed30ac4774d17bac42885096373f6949cead1bbb4d81c226ff8dd1c59361b824760c046027fa5470bf65fb416002a8c564f2b577f
7
+ data.tar.gz: 42b6c6c956e45ab5352c1e9f93a5210c188fa129df7c24da1ca8efec6781baa820564a1bce965fc00176c69ab25273e8873c1220c821899ee14ce210c267bee4
@@ -500,6 +500,21 @@ module PostHog
500
500
  end
501
501
  end
502
502
 
503
+ def self.parse_finite_number(value)
504
+ case value
505
+ when String
506
+ return unless /\A[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)?\z/.match?(value)
507
+ when Integer, Float
508
+ # JSON numbers remain supported alongside numeric strings.
509
+ else
510
+ return unless defined?(::BigDecimal) && value.is_a?(::BigDecimal)
511
+ end
512
+
513
+ number = value.to_f
514
+ number if number.finite?
515
+ end
516
+ private_class_method :parse_finite_number
517
+
503
518
  def self.relative_date_parse_for_feature_flag_matching(value)
504
519
  match = /^-?([0-9]+)([a-z])$/.match(value)
505
520
  parsed_dt = DateTime.now.new_offset(0)
@@ -734,20 +749,13 @@ module PostHog
734
749
  when 'not_regex'
735
750
  PostHog::Utils.is_valid_regex(value.to_s) && Regexp.new(value.to_s).match(override_value.to_s).nil?
736
751
  when 'gt', 'gte', 'lt', 'lte'
737
- parsed_value = nil
738
- begin
739
- parsed_value = Float(value)
740
- rescue StandardError # rubocop:disable Lint/SuppressedException
741
- end
742
- if !parsed_value.nil? && !override_value.nil?
743
- if override_value.is_a?(String)
744
- compare(override_value, value.to_s, operator)
745
- else
746
- compare(override_value, parsed_value, operator)
747
- end
748
- else
749
- compare(override_value.to_s, value.to_s, operator)
750
- end
752
+ parsed_value = parse_finite_number(value)
753
+ raise InconclusiveMatchError, 'Invalid numeric condition' if parsed_value.nil?
754
+
755
+ parsed_override = parse_finite_number(override_value)
756
+ return false if parsed_override.nil?
757
+
758
+ compare(parsed_override, parsed_value, operator)
751
759
  when 'is_date_before', 'is_date_after'
752
760
  override_date = PostHog::Utils.convert_to_datetime(override_value.to_s)
753
761
  parsed_date = relative_date_parse_for_feature_flag_matching(value.to_s)
@@ -1110,6 +1118,13 @@ module PostHog
1110
1118
  groups: {}, group_properties: {}, snapshot: _evaluation_snapshot)
1111
1119
  flag_filters = flag[:filters] || {}
1112
1120
 
1121
+ # Holdouts precede release conditions: a held-out identifier is excluded from
1122
+ # the flag's targeting entirely rather than bucketed into one of its variants.
1123
+ # The per-condition aggregation handled below never changes holdout membership,
1124
+ # so this uses the flag-level bucketing identity the caller resolved.
1125
+ holdout_variant = holdout_variant_for(flag_filters[:holdout], distinct_id)
1126
+ return holdout_variant unless holdout_variant.nil?
1127
+
1113
1128
  flag_conditions = flag_filters[:groups] || []
1114
1129
  flag_aggregation = flag_filters[:aggregation_group_type_index]
1115
1130
  early_exit = flag_filters[:early_exit] == true
@@ -1233,6 +1248,36 @@ module PostHog
1233
1248
  (Integer(hash_key[0..14], 16).to_f / 0xfffffffffffffff)
1234
1249
  end
1235
1250
 
1251
+ # An experiment holdout excludes an identifier from the flag's release conditions
1252
+ # entirely, resolving it to the synthetic variant "holdout-<id>". That variant does
1253
+ # not need to exist in `filters.multivariate.variants`. Returns nil when the flag has
1254
+ # no usable holdout or the identifier falls outside it, leaving ordinary evaluation
1255
+ # unchanged.
1256
+ def holdout_variant_for(holdout, bucketing_value)
1257
+ return nil unless holdout.is_a?(Hash)
1258
+
1259
+ id = holdout[:id]
1260
+ exclusion_percentage = holdout[:exclusion_percentage]
1261
+ return nil if id.nil? || !exclusion_percentage.is_a?(Numeric)
1262
+
1263
+ # The server clamps an out-of-range percentage rather than rejecting it, and treats
1264
+ # 100 as everyone without hashing, so a full holdout can't miss on a hash boundary.
1265
+ # Fractional percentages are kept as-is.
1266
+ percentage = exclusion_percentage.to_f.clamp(0, 100)
1267
+ return nil if percentage < 100 && _holdout_hash(bucketing_value) > (percentage / 100)
1268
+
1269
+ "holdout-#{id}"
1270
+ end
1271
+
1272
+ # Holdout membership hashes `holdout-<bucketing value>` with no separator, salt, flag
1273
+ # key or holdout id taking part, so one identity lands in the same holdout population
1274
+ # on every flag, the way the server buckets it. The dot-separated flag hash above
1275
+ # selects a different population and must not be reused here.
1276
+ def _holdout_hash(bucketing_value)
1277
+ hash_key = Digest::SHA1.hexdigest "holdout-#{bucketing_value}"
1278
+ (Integer(hash_key[0..14], 16).to_f / 0xfffffffffffffff)
1279
+ end
1280
+
1236
1281
  def get_matching_variant(flag, distinct_id)
1237
1282
  hash_value = _hash(flag[:key], distinct_id, 'variant')
1238
1283
  matching_variant = variant_lookup_table(flag).find do |variant|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.27.1'
4
+ VERSION = '3.28.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.27.1
4
+ version: 3.28.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''