gitlab-experiment 0.3.0 → 0.3.1

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: 6134f703a49eb7411ff59e1fa7778421890498a537419cd765a99c5e07ff1523
4
- data.tar.gz: ea3736188b46c9527818109dc87839c33937e0c9086bae4464992046f425874a
3
+ metadata.gz: 4bb028b4495b7ab210c13769433a8b6ec7b8a3fc459a2c33f0e9bc650cf23916
4
+ data.tar.gz: '0387ed9d7e722c4ba6bce42aed1b71720b6df23b6687100b02186f57b6f125c9'
5
5
  SHA512:
6
- metadata.gz: ec048634699257e018d7e67f290dfa2dd5e2712d58b1ef25eeb1c9353c5a23ad2f7a8ec0484493e6bccaabc57801aa22ceb8632a5a8c355652ae4a5541a43286
7
- data.tar.gz: 51f63fb0256c49f393887451723483233927a0a983c51ca80f98494634e156dab28d0f87f21319a4df750392bb8329923e94ab23091929b3b26904edb25ce5b3
6
+ metadata.gz: d27ae9c243b447d994060bc2250ade8be78351312c01fa591e67441f913fd67f9e2caed1de77caac454b0a6b84702ff865e6a58c796c8e014ba2cf530dd5df9b
7
+ data.tar.gz: 2a3dcfef0dbfeb7e9e35d3ca56ede0bc7d1feeeafa9774a0f9184eeb89dfe49a49e6fbc93f594332cda1d8c87b374069a0ab1c053ab51183d8fdf47af4769845
data/README.md CHANGED
@@ -27,7 +27,7 @@ gem 'gitlab-experiment'
27
27
  If you're using Rails, you can install the initializer. It provides basic configuration and documentation.
28
28
 
29
29
  ```shell
30
- $ rails generate gitlab-experiment:install
30
+ $ rails generate gitlab_experiment:install
31
31
  ```
32
32
 
33
33
  ## Implementing an experiment
@@ -5,7 +5,7 @@ Gitlab::Experiment.configure do |config|
5
5
  config.name_prefix = nil
6
6
 
7
7
  # The logger is used to log various details of the experiments.
8
- config.logger = Logger.new(STDOUT)
8
+ config.logger = Logger.new($stdout)
9
9
 
10
10
  # The caching layer is expected to respond to fetch, like Rails.cache.
11
11
  config.cache = nil
@@ -22,11 +22,17 @@ module Gitlab
22
22
  end
23
23
 
24
24
  def run(name, variant_name = nil, **context, &block)
25
- instance = new(name, variant_name, **context, &block)
25
+ instance = constantize(name).new(name, variant_name, **context, &block)
26
26
  return instance unless block_given?
27
27
 
28
28
  instance.context.frozen? ? instance.run : instance.tap(&:run)
29
29
  end
30
+
31
+ def constantize(name)
32
+ name = "#{name}_experiment"
33
+ klass = name.respond_to?(:classify) ? name.classify.safe_constantize : nil
34
+ klass || self
35
+ end
30
36
  end
31
37
 
32
38
  def initialize(name, variant_name = nil, **context)
@@ -98,6 +104,15 @@ module Gitlab
98
104
  @excluded.any? { |exclude| exclude.call(self) }
99
105
  end
100
106
 
107
+ def id
108
+ "#{name}:#{signature[:key]}"
109
+ end
110
+ alias_method :session_id, :id
111
+
112
+ def flipper_id
113
+ "Experiment;#{id}"
114
+ end
115
+
101
116
  protected
102
117
 
103
118
  def generate_result(variant_name)
@@ -13,7 +13,7 @@ module Gitlab
13
13
  @name_prefix = nil
14
14
 
15
15
  # The logger is used to log various details of the experiments.
16
- @logger = Logger.new(STDOUT)
16
+ @logger = Logger.new($stdout)
17
17
 
18
18
  # Cache layer. Expected to respond to fetch, like Rails.cache.
19
19
  @cache = nil
@@ -41,8 +41,15 @@ module Gitlab
41
41
  end
42
42
 
43
43
  class << self
44
- attr_accessor :name_prefix, :logger, :cache
45
- attr_accessor :variant_resolver, :tracking_behavior, :publishing_behavior, :context_hash_strategy
44
+ attr_accessor(
45
+ :name_prefix,
46
+ :logger,
47
+ :cache,
48
+ :variant_resolver,
49
+ :tracking_behavior,
50
+ :publishing_behavior,
51
+ :context_hash_strategy
52
+ )
46
53
  end
47
54
  end
48
55
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  class Experiment
5
- VERSION = '0.3.0'
5
+ VERSION = '0.3.1'
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-21 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scientist