gitlab-experiment 0.4.10 → 0.4.11

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: a1cbae46377202f37922a880d0c1cde571de29e96dd14fbe879e05718ba6d8ea
4
- data.tar.gz: 48258191a1de1e9ca5de40428d481466c3a68272422783610dbfbd112a834ea7
3
+ metadata.gz: 207b046a8c0b1c98ad958442716be6a8232c431bfcc702a42817d8eb1aa3f465
4
+ data.tar.gz: c654346312abfd1684af031fe1784cb1db61ac583c0c52c3ef50b08d0337182b
5
5
  SHA512:
6
- metadata.gz: 8b7d5b2e1725e988bc55653baa1ece89c2d4b31f9cafc7e4d563bc6c093071abdf8fea89abf758658740f34168eb185a01beada94d331e85bf6c9b5cad78a345
7
- data.tar.gz: cb295e0547616c5c7b47bcec319e27693e7017bbf14a0026b02afb6324715922a01620485db0878cf806f3ac89306f22e812cd44b812da871e3dc77157aa2386
6
+ metadata.gz: 3f3b9d02b8a268e99bb9cda60e7c1a76d55962f9d04754209558deebd58624c5407bf883a6405c3d248b13f3a246a96a9d4a370bfca052e512f125a57aa89e8f
7
+ data.tar.gz: b43611c028598b362972079b6b785dd62e7c4b35dffa2abc6bd9822a6a2b488385101a5aea975b0d6c429638a8e8661ff6e8aca9e0a0e184c9510a6e5c591d48
@@ -79,11 +79,8 @@ module Gitlab
79
79
  end
80
80
 
81
81
  def variant(value = nil)
82
- if value.blank? && @variant_name || @resolving_variant
83
- return Variant.new(name: (@variant_name || :unresolved).to_s)
84
- end
85
-
86
82
  @variant_name = value unless value.blank?
83
+ return Variant.new(name: (@variant_name || :unresolved).to_s) if @variant_name || @resolving_variant
87
84
 
88
85
  if enabled?
89
86
  @variant_name ||= :control if excluded?
@@ -94,18 +91,16 @@ module Gitlab
94
91
  end
95
92
  end
96
93
 
97
- Variant.new(name: (@variant_name || :control).to_s)
94
+ run_callbacks(segmentation_callback_chain) do
95
+ @variant_name ||= :control
96
+ Variant.new(name: @variant_name.to_s)
97
+ end
98
98
  ensure
99
99
  @resolving_variant = false
100
100
  end
101
101
 
102
102
  def run(variant_name = nil)
103
- @result ||= begin
104
- variant_name = variant(variant_name).name
105
- run_callbacks(run_with_segmenting? ? :segmented_run : :unsegmented_run) do
106
- super(@variant_name ||= variant_name)
107
- end
108
- end
103
+ @result ||= super(variant(variant_name).name)
109
104
  end
110
105
 
111
106
  def publish(result)
@@ -158,7 +153,9 @@ module Gitlab
158
153
  end
159
154
 
160
155
  def excluded?
161
- @excluded ||= !@context.trackable? || # adhere to DNT headers
156
+ return @excluded if defined?(@excluded)
157
+
158
+ @excluded = !@context.trackable? || # adhere to DNT headers
162
159
  !run_callbacks(:exclusion_check) { :not_excluded } # didn't pass exclusion check
163
160
  end
164
161
 
@@ -172,8 +169,10 @@ module Gitlab
172
169
 
173
170
  protected
174
171
 
175
- def run_with_segmenting?
176
- !variant_assigned? && enabled? && !excluded?
172
+ def segmentation_callback_chain
173
+ return :segmentation_check if !variant_assigned? && enabled? && !excluded?
174
+
175
+ :unsegmented
177
176
  end
178
177
 
179
178
  def variant_assigned?
@@ -7,8 +7,8 @@ module Gitlab
7
7
  include ActiveSupport::Callbacks
8
8
 
9
9
  included do
10
- define_callbacks(:unsegmented_run)
11
- define_callbacks(:segmented_run)
10
+ define_callbacks(:unsegmented)
11
+ define_callbacks(:segmentation_check)
12
12
  define_callbacks(:exclusion_check, skip_after_callbacks_if_terminated: true)
13
13
  end
14
14
 
@@ -34,7 +34,7 @@ module Gitlab
34
34
 
35
35
  raise ArgumentError, 'no filters provided' if filters.empty?
36
36
 
37
- set_callback(:segmented_run, :before, *filters, options)
37
+ set_callback(:segmentation_check, :before, *filters, options)
38
38
  end
39
39
  end
40
40
  end
@@ -86,7 +86,7 @@ module Gitlab
86
86
  experiment.context(context)
87
87
 
88
88
  experiment.instance_variable_set(ivar, nil)
89
- experiment.run_callbacks(:segmented_run)
89
+ experiment.run_callbacks(:segmentation_check)
90
90
 
91
91
  @actual = experiment.instance_variable_get(ivar)
92
92
  @expected ? @actual.to_s == @expected.to_s : @actual.present?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  class Experiment
5
- VERSION = '0.4.10'
5
+ VERSION = '0.4.11'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-experiment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-16 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport