posthog-ruby 2.0.0 → 2.2.0

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: 0f9f2eb496ae894a6481be1072bdea6c38dbbc7f115e433994a559efd4f906e8
4
- data.tar.gz: 71af8b9c90bb49b9d8816a4eb579a38a93dc4886da74827c0548ff2b4e206206
3
+ metadata.gz: 57e103be9e2b8f115f96e948f0e82fd138b3c9ec9a7fe6fb1e1cff2e0c29b658
4
+ data.tar.gz: c275ab93b048fda6bd2e5fa65c8e1955296536b6a281405974db2460b941a626
5
5
  SHA512:
6
- metadata.gz: a15603ba1c590a123d0cc086343c77e4b9239a2fea94ed7c99f37756f869c27e3b07705fd9e45c3cce75e4a6a64ae79fd1c26e9c1515ceeacb172ef214ee2800
7
- data.tar.gz: be40d32a621aea85c184c39499dff819eeec6a51d953c5f5dba4446262811c97b3bd5e96b28c3767f01588da2ba207a9a82fe678df9fb915fe701d4671357620
6
+ metadata.gz: 05cfc7dc4717b287287a37acd50680db1805ef41e42524feaabfd1b3113d96a1d5a90873b453f257e568ff75ce2d6a0e8db4ee82e26210ac280c628970bbed79
7
+ data.tar.gz: 7ca3acb35caa156e76b06bec03d13494b54a06fb6b727a6601c19d6cbb2e04437bb7873cb3e1e9534303042b84a34bbf35deba36e243bc843a7a89baeef278ac
@@ -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.2.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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-12 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: 1.1.10
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: 1.1.10
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: commander
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -169,7 +163,7 @@ homepage: https://github.com/PostHog/posthog-ruby
169
163
  licenses:
170
164
  - MIT
171
165
  metadata: {}
172
- post_install_message:
166
+ post_install_message:
173
167
  rdoc_options: []
174
168
  require_paths:
175
169
  - lib
@@ -184,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
178
  - !ruby/object:Gem::Version
185
179
  version: '0'
186
180
  requirements: []
187
- rubygems_version: 3.1.2
188
- signing_key:
181
+ rubygems_version: 3.1.6
182
+ signing_key:
189
183
  specification_version: 4
190
184
  summary: PostHog library
191
185
  test_files: []