easy_ab 0.1.0 → 0.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
  SHA1:
3
- metadata.gz: be25942ed3b823b7bf8b4445eee642f884d6cff2
4
- data.tar.gz: dc77331ec7b69a4a4c0f3cca37e3d7cd46b922bc
3
+ metadata.gz: a1eeea1cbf4338159b42eb100e86cf1bae045b7a
4
+ data.tar.gz: dbdb41940f2da5113a705c30bc290934219666b7
5
5
  SHA512:
6
- metadata.gz: 780ccb7138c2e6d0671fe6d2b1eda79cd04b68e517c941e22ce4fab91a89b31a937297a0e5f103e947db5c6d3e23fcdd3f33b0262f890039a6d90118d2674920
7
- data.tar.gz: 11c2df2ef9ab91699e7c52b05894aff91fcaeb273d82a4adccee60849a943824f8b6cd2e42323501d8ef6f33ff059b61b604da29563b0cfeb0c93b2420403822
6
+ metadata.gz: 4b2465ffa608c615f52c9f2a3c153323848d2a5d5c8871a906e33492ba927da27a6890b6c1baf524f72e02045907d67906f2619d36e78559e3720af7900f939d
7
+ data.tar.gz: 00525589553175a0feac4fc7cf4f2b1c7936885792009f08e82393f988638723c9d593b31db63f9ef1ed27bdaecd3ed72266928beddd51ecc7275f280bd74c6a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
+ # 0.2.0 (2017-08-15)
2
+ * **API change**: If all rules failed, `ab_test` returns nil, instead of the first variant.
3
+
1
4
  # 0.1.0
2
5
  * Support winner
3
6
 
4
7
  # 0.0.3
5
- * Add new API `all_participated_experiments` to list current user's all participated experiments
8
+ * Add new API `all_participated_experiments` to list current user's all participated experiments
9
+
10
+ # 0.0.1
11
+ * The first version :)
data/README.md CHANGED
@@ -114,21 +114,39 @@ EasyAb.experiments do |experiment|
114
114
  end
115
115
  ```
116
116
 
117
- NOTICE: rules are executed in the order you defined in `config/initializers/easy_ab.rb`. If there are intersections among your rules, the former rule will be applied. For example:
117
+ NOTICE: rules are executed in the order you defined in `config/initializers/easy_ab.rb`. If there exists logic overlap among your rules, the former rule will be applied. For example:
118
118
 
119
119
  ```ruby
120
+ # config/initializers/easy_ab.rb
120
121
  EasyAb.experiments do |experiment|
121
122
  experiment.define :extra_vip_duration,
122
123
  variants: ['90', '30']
123
124
  rules: [
124
- -> { current_user.id <= 20 },
125
- -> { current_user.id > 10 }
125
+ -> { true },
126
+ -> { true }
126
127
  ]
127
128
 
128
- # Users with id between 11 to 20 matches both lambdas, will get variant '90'
129
+ # view
130
+ easy_ab(:extra_vip_duration) # => '90'
129
131
  ```
130
132
 
131
- Keep in mind that `ab_test()` helper always returns String. You have to handle the type conversion by yourself.
133
+ If all rules are not passed, returns nil:
134
+
135
+ ```ruby
136
+ # config/initializers/easy_ab.rb
137
+ EasyAb.experiments do |experiment|
138
+ experiment.define :extra_vip_duration,
139
+ variants: ['90', '30']
140
+ rules: [
141
+ -> { false },
142
+ -> { false }
143
+ ]
144
+
145
+ # view
146
+ ab_test(:extra_vip_duration) # => nil
147
+ ```
148
+
149
+ Keep in mind that `ab_test()` helper always returns String (or nil). You have to handle the type conversion by yourself.
132
150
 
133
151
  ```ruby
134
152
  # In controller
@@ -32,6 +32,7 @@ module EasyAb
32
32
  grouping.variant = options[:variant].to_s
33
33
  else
34
34
  grouping.variant ||= flexible_variant(options[:contexted_rules])
35
+ return nil if grouping.variant.nil?
35
36
  end
36
37
 
37
38
  if grouping.changed? && !options[:skip_save]
@@ -94,8 +95,9 @@ module EasyAb
94
95
  contexted_rules.each_with_index do |rule, i|
95
96
  return variants[i] if rule.call
96
97
  end
97
- # If all rules not matched, apply the first variatn
98
- variants.first
98
+
99
+ # If all rules not matched, return nil
100
+ nil
99
101
  end
100
102
 
101
103
  def weighted_variant
@@ -1,3 +1,3 @@
1
1
  module EasyAb
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_ab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Chu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-09 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: icarus4.chu@gmail.com