gitlab-experiment 0.4.4 → 0.4.5
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 +4 -4
- data/README.md +1 -1
- data/lib/gitlab/experiment.rb +17 -7
- data/lib/gitlab/experiment/callbacks.rb +4 -15
- data/lib/gitlab/experiment/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81476752521c6ead83308324fdcf360db7b8182bab340c9ffe7ad4eec21b998e
|
4
|
+
data.tar.gz: 006d94ff92104bef820be7d6c7c9638b20a6e0a4a533439fca056b4cba31a0bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5644f3cf6798ddc27034b8857cf03bb77904b3b5c8a80b84c398134ad143b919e16ddc23746a58e63b71d0464c92ec5cce682ddb2039e471b55cfeb42e3cd4a
|
7
|
+
data.tar.gz: 2dd2adf62427f96a9745d9681ee87b5621acf43fc4dae33ffefdadfad5af6ec3a0ad1e79e601a4d6260e61fa64faf635af9ae753e3fb474e033af7d2d7d55381
|
data/README.md
CHANGED
@@ -341,7 +341,7 @@ Gitlab::Experiment.configure do |config|
|
|
341
341
|
end
|
342
342
|
```
|
343
343
|
|
344
|
-
More examples for configuration are available in the provided [rails initializer](lib/generators/gitlab/experiment/install/templates/initializer.rb).
|
344
|
+
More examples for configuration are available in the provided [rails initializer](lib/generators/gitlab/experiment/install/templates/initializer.rb.tt).
|
345
345
|
|
346
346
|
### Client layer / JavaScript
|
347
347
|
|
data/lib/gitlab/experiment.rb
CHANGED
@@ -30,7 +30,7 @@ module Gitlab
|
|
30
30
|
raise ArgumentError, 'name is required' if name.nil? && base?
|
31
31
|
|
32
32
|
instance = constantize(name).new(name, variant_name, **context, &block)
|
33
|
-
return instance unless
|
33
|
+
return instance unless block
|
34
34
|
|
35
35
|
instance.context.frozen? ? instance.run : instance.tap(&:run)
|
36
36
|
end
|
@@ -58,9 +58,9 @@ module Gitlab
|
|
58
58
|
raise ArgumentError, 'name is required' if name.blank? && self.class.base?
|
59
59
|
|
60
60
|
@name = self.class.experiment_name(name, suffix: false)
|
61
|
-
@variant_name = variant_name
|
62
61
|
@excluded = []
|
63
62
|
@context = Context.new(self, **context)
|
63
|
+
@variant_name = cache_variant(variant_name) { nil } if variant_name.present?
|
64
64
|
|
65
65
|
exclude { !@context.trackable? }
|
66
66
|
compare { false }
|
@@ -102,11 +102,7 @@ module Gitlab
|
|
102
102
|
@result ||= begin
|
103
103
|
variant_name = variant(variant_name).name
|
104
104
|
run_callbacks(variant_assigned? ? :unsegmented_run : :segmented_run) do
|
105
|
-
|
106
|
-
behaviors[variant_name] ||= -> { send(behavior_name) } # rubocop:disable GitlabSecurity/PublicSend
|
107
|
-
end
|
108
|
-
|
109
|
-
super(@variant_name = variant_name)
|
105
|
+
super(@variant_name ||= variant_name)
|
110
106
|
end
|
111
107
|
end
|
112
108
|
end
|
@@ -129,6 +125,20 @@ module Gitlab
|
|
129
125
|
@variant_names ||= behaviors.keys.map(&:to_sym) - [:control]
|
130
126
|
end
|
131
127
|
|
128
|
+
def behaviors
|
129
|
+
@behaviors ||= public_methods.each_with_object(super) do |name, behaviors|
|
130
|
+
next unless name.end_with?('_behavior')
|
131
|
+
|
132
|
+
behavior_name = name.to_s.sub(/_behavior$/, '')
|
133
|
+
behaviors[behavior_name] ||= -> { send(name) } # rubocop:disable GitlabSecurity/PublicSend
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def try(name = nil, &block)
|
138
|
+
name = (name || 'candidate').to_s
|
139
|
+
behaviors[name] = block
|
140
|
+
end
|
141
|
+
|
132
142
|
def signature
|
133
143
|
{ variant: variant.name, experiment: name }.merge(context.signature)
|
134
144
|
end
|
@@ -7,31 +7,20 @@ module Gitlab
|
|
7
7
|
include ActiveSupport::Callbacks
|
8
8
|
|
9
9
|
included do
|
10
|
-
define_callbacks(
|
11
|
-
|
12
|
-
skip_after_callbacks_if_terminated: true
|
13
|
-
)
|
14
|
-
|
15
|
-
define_callbacks(
|
16
|
-
:segmented_run,
|
17
|
-
skip_after_callbacks_if_terminated: false,
|
18
|
-
terminator: lambda do |target, result_lambda|
|
19
|
-
result_lambda.call
|
20
|
-
target.variant_assigned?
|
21
|
-
end
|
22
|
-
)
|
10
|
+
define_callbacks(:unsegmented_run)
|
11
|
+
define_callbacks(:segmented_run)
|
23
12
|
end
|
24
13
|
|
25
14
|
class_methods do
|
26
15
|
def segment(*filter_list, variant:, **options, &block)
|
27
16
|
filters = filter_list.unshift(block).compact.map do |filter|
|
28
17
|
result_lambda = ActiveSupport::Callbacks::CallTemplate.build(filter, self).make_lambda
|
29
|
-
->(target) { target.variant(variant) if result_lambda.call(target, nil) }
|
18
|
+
->(target) { target.variant(variant) if !target.variant_assigned? && result_lambda.call(target, nil) }
|
30
19
|
end
|
31
20
|
|
32
21
|
raise ArgumentError, 'no filters provided' if filters.empty?
|
33
22
|
|
34
|
-
set_callback(:segmented_run, :before, *filters, options
|
23
|
+
set_callback(:segmented_run, :before, *filters, options)
|
35
24
|
end
|
36
25
|
end
|
37
26
|
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.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|