posthog-ruby 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f9f2eb496ae894a6481be1072bdea6c38dbbc7f115e433994a559efd4f906e8
4
- data.tar.gz: 71af8b9c90bb49b9d8816a4eb579a38a93dc4886da74827c0548ff2b4e206206
3
+ metadata.gz: ef38f429ce00bcdcfc5c861fd163c420b9b3823b7cbcef4019a8bad580a6ad6f
4
+ data.tar.gz: '08effac4bc47b38a6e67fe2f578cd67a974a7462dcaa6e73e92ac11b5bb34333'
5
5
  SHA512:
6
- metadata.gz: a15603ba1c590a123d0cc086343c77e4b9239a2fea94ed7c99f37756f869c27e3b07705fd9e45c3cce75e4a6a64ae79fd1c26e9c1515ceeacb172ef214ee2800
7
- data.tar.gz: be40d32a621aea85c184c39499dff819eeec6a51d953c5f5dba4446262811c97b3bd5e96b28c3767f01588da2ba207a9a82fe678df9fb915fe701d4671357620
6
+ metadata.gz: 86892110210900d5a3faa13fe2c335ce7d1ce0390390ff25c3d8a29510187d8829bda4795ead866471aaab7fa333f50a9b8251ff8e4ae47411d7a601d9f15eb2
7
+ data.tar.gz: 80374572728723780c1930555491445a4761685df6574305c0de73f9d0fbd1630924c5fd4412b469f735bd44d7657b7160d73ccb4094c978b58bb7494950bb32
@@ -196,6 +196,14 @@ class PostHog
196
196
  override_value.class == value.class && override_value < value
197
197
  when 'lte'
198
198
  override_value.class == value.class && override_value <= value
199
+ when 'is_date_before', 'is_date_after'
200
+ parsed_date = PostHog::Utils::convert_to_datetime(value)
201
+ override_date = PostHog::Utils::convert_to_datetime(override_value)
202
+ if operator == 'is_date_before'
203
+ return override_date < parsed_date
204
+ else
205
+ return override_date > parsed_date
206
+ end
199
207
  else
200
208
  logger.error "Unknown operator: #{operator}"
201
209
  false
@@ -247,10 +255,22 @@ class PostHog
247
255
  is_inconclusive = false
248
256
  result = nil
249
257
 
250
- flag_conditions.each do |condition|
258
+ # Stable sort conditions with variant overrides to the top. This ensures that if overrides are present, they are
259
+ # evaluated first, and the variant override is applied to the first matching condition.
260
+ sorted_flag_conditions = flag_conditions.each_with_index.sort_by { |condition, idx| [condition[:variant].nil? ? 1 : -1, idx] }
261
+
262
+ sorted_flag_conditions.each do |condition, idx|
251
263
  begin
252
264
  if is_condition_match(flag, distinct_id, condition, properties)
253
- result = get_matching_variant(flag, distinct_id) || true
265
+ variant_override = condition[:variant]
266
+ flag_multivariate = flag_filters[:multivariate] || {}
267
+ flag_variants = flag_multivariate[:variants] || []
268
+ if flag_variants.map{|variant| variant[:key]}.include?(condition[:variant])
269
+ variant = variant_override
270
+ else
271
+ variant = get_matching_variant(flag, distinct_id)
272
+ end
273
+ result = variant || true
254
274
  break
255
275
  end
256
276
  rescue InconclusiveMatchError => e
data/lib/posthog/utils.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require 'securerandom'
2
2
 
3
3
  class PostHog
4
+
5
+ class InconclusiveMatchError < StandardError
6
+ end
7
+
4
8
  module Utils
5
9
  extend self
6
10
 
@@ -83,6 +87,22 @@ class PostHog
83
87
  ]
84
88
  end
85
89
 
90
+ def convert_to_datetime(value)
91
+ if value.respond_to?(:strftime)
92
+ parsed_date = value
93
+ return parsed_date
94
+ elsif value.respond_to?(:to_str)
95
+ begin
96
+ parsed_date = DateTime.parse(value)
97
+ return parsed_date
98
+ rescue ArgumentError => e
99
+ raise InconclusiveMatchError.new("#{value} is not in a valid date format")
100
+ end
101
+ else
102
+ raise InconclusiveMatchError.new("The date provided must be a string or date object")
103
+ end
104
+ end
105
+
86
106
  UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
87
107
  UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
88
108
 
@@ -1,3 +1,3 @@
1
1
  class PostHog
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-12 00:00:00.000000000 Z
11
+ date: 2022-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby