activeexperiment 0.1.0.alpha → 0.1.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -15
- data/lib/active_experiment/gem_version.rb +1 -1
- data/lib/active_experiment/rollouts.rb +5 -0
- 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: dbb349cf57adaf426eb37b7e2ed5124bf321e674ef0116ab6e7ff6a5cf65fbae
|
4
|
+
data.tar.gz: a7f74b8b717b4c34712a09e8792745333fc2b4ee3616202555857f87f8651010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3477a95ecb87731bef45429864595b1428c8c6b576f47a4911158272e582f558420b6757992a8f0f86b3678bbbe0fda9ff091387ae312d770bfacf4857f76224
|
7
|
+
data.tar.gz: 483970d7592e90564bf48f38a8504d6d6ac10d633eb2687617cc26ea77c38b8def22a46c58194ed8dfa2b52334a127c69b4239189b93dab0dd1c9ea704f033de
|
data/README.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/activeexperiment.svg)](https://badge.fury.io/rb/activeexperiment)
|
2
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/551c00c66f8558c7a01b/maintainability)](https://codeclimate.com/github/jejacks0n/active_experiment/maintainability)
|
3
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/551c00c66f8558c7a01b/test_coverage)](https://codeclimate.com/github/jejacks0n/active_experiment/test_coverage)
|
4
|
+
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
|
5
|
+
|
1
6
|
# Active Experiment – Decide what to do next
|
2
7
|
|
3
8
|
Active Experiment is a framework for defining and running experiments. It supports using a variety of rollout and reporting strategies and/or services.
|
@@ -58,7 +63,11 @@ gem install activeexperiment
|
|
58
63
|
|
59
64
|
Source code can be downloaded as part of the project on GitHub:
|
60
65
|
|
61
|
-
* https://github.com/jejacks0n/
|
66
|
+
* https://github.com/jejacks0n/active_experiment
|
67
|
+
|
68
|
+
Adapters can be added to integrate with various services:
|
69
|
+
|
70
|
+
- [Unleash adapter](https://github.com/jejacks0n/activeexperiment-unleash)
|
62
71
|
|
63
72
|
## Advanced Experimentation
|
64
73
|
|
@@ -145,6 +154,8 @@ Project specific rollouts can be defined and registered too. To illustrate, here
|
|
145
154
|
|
146
155
|
```ruby
|
147
156
|
class FeatureFlagRollout < ActiveExperiment::Rollouts::BaseRollout
|
157
|
+
register_as :feature_flag
|
158
|
+
|
148
159
|
def skipped_for(experiment)
|
149
160
|
!Feature.enabled?(@rollout_options[:flag_name] || experiment.name)
|
150
161
|
end
|
@@ -153,8 +164,6 @@ class FeatureFlagRollout < ActiveExperiment::Rollouts::BaseRollout
|
|
153
164
|
experiment.variant_names.sample
|
154
165
|
end
|
155
166
|
end
|
156
|
-
|
157
|
-
ActiveExperiment::Rollouts.register(:feature_flag, FeatureRollout)
|
158
167
|
```
|
159
168
|
|
160
169
|
This rollout can now be used the same way the built-in rollouts are:
|
@@ -165,7 +174,7 @@ class MyExperiment < ActiveExperiment::Base
|
|
165
174
|
variant(:blue) { "blue" }
|
166
175
|
|
167
176
|
# Using a custom rollout with options.
|
168
|
-
|
177
|
+
use_rollout :feature_flag, flag_name: "my_feature_flag"
|
169
178
|
end
|
170
179
|
```
|
171
180
|
|
@@ -206,7 +215,9 @@ Some simple reporting strategies might simply be added to `after_run` callbacks,
|
|
206
215
|
A subscriber can be used to listen for experiment events and report them to a service. For example, here's a subscriber that reports to a fictional analytics service:
|
207
216
|
|
208
217
|
```ruby
|
209
|
-
class MyAnalyticsSubscriber
|
218
|
+
class MyAnalyticsSubscriber < ActiveSupport::Subscriber
|
219
|
+
attach_to :active_experiment
|
220
|
+
|
210
221
|
def process_run(event)
|
211
222
|
experiment = event.payload[:experiment]
|
212
223
|
return if experiment.skipped?
|
@@ -217,8 +228,6 @@ class MyAnalyticsSubscriber
|
|
217
228
|
)
|
218
229
|
end
|
219
230
|
end
|
220
|
-
|
221
|
-
MyAnalyticsSubscriber.attach_to(:active_experiment)
|
222
231
|
```
|
223
232
|
|
224
233
|
The following Active Experiment events are available for subscribers:
|
@@ -266,7 +275,7 @@ end
|
|
266
275
|
<summary>Expand ERB example</summary>
|
267
276
|
|
268
277
|
```erb
|
269
|
-
<%== MyExperiment.set(capture: self).run do |experiment| %>
|
278
|
+
<%== MyExperiment.set(capture: self).run(current_user) do |experiment| %>
|
270
279
|
<div class="container">
|
271
280
|
<%= experiment.on(:red) do %>
|
272
281
|
<button class="red-pill">Red</button>
|
@@ -279,6 +288,19 @@ end
|
|
279
288
|
```
|
280
289
|
</details>
|
281
290
|
|
291
|
+
If you don't need to capture the experiment, simply run like you would anywhere else:
|
292
|
+
|
293
|
+
```erb
|
294
|
+
<% MyExperiment.run(current_user) do |experiment| %>
|
295
|
+
<% experiment.on(:red) do %>
|
296
|
+
<button class="red-pill">Red</button>
|
297
|
+
<% end %>
|
298
|
+
<% experiment.on(:blue) do %>
|
299
|
+
<button class="blue-pill">Blue</button>
|
300
|
+
<% end %>
|
301
|
+
<% end %>
|
302
|
+
```
|
303
|
+
|
282
304
|
## Client Side Experimentation
|
283
305
|
|
284
306
|
While Active Experiment doesn't include any specific tooling for client side experimentation at this time, it does provide the ability to surface experiments in the client layer.
|
@@ -297,7 +319,7 @@ In the layout, the experiment data can be rendered as JSON for instance:
|
|
297
319
|
Or each experiment can be iterated over and rendered individually:
|
298
320
|
|
299
321
|
```erb
|
300
|
-
<% ActiveExperiment::Executed.
|
322
|
+
<% ActiveExperiment::Executed.as_array.each do |experiment| %>
|
301
323
|
<meta name="<%= experiment.name %>" content="<%== experiment.serialize.to_json %>">
|
302
324
|
<% end %>
|
303
325
|
```
|
@@ -323,7 +345,7 @@ test "stubbing experiments" do
|
|
323
345
|
end
|
324
346
|
|
325
347
|
stub_experiment(MyExperiment, skip: true) do
|
326
|
-
# Now all MyExperiment experiments be skipped.
|
348
|
+
# Now all MyExperiment experiments will be skipped.
|
327
349
|
end
|
328
350
|
end
|
329
351
|
```
|
@@ -332,24 +354,24 @@ Assertion helpers are also available:
|
|
332
354
|
|
333
355
|
```ruby
|
334
356
|
test "asserting experiments" do
|
335
|
-
# no experiments
|
357
|
+
# Assert that no experiments have been run.
|
336
358
|
assert_no_experiments
|
337
359
|
|
338
360
|
MyExperiment.run(id: 1)
|
339
361
|
|
340
|
-
# 1 experiment has been run
|
362
|
+
# Assert that 1 experiment has been run.
|
341
363
|
assert_experiments 1
|
342
364
|
|
343
|
-
#
|
365
|
+
# Assert that within the block, 2 experiments will be run.
|
344
366
|
assert_experiments 2 do
|
345
367
|
MyExperiment.run(id: 2)
|
346
368
|
MyExperiment.run(id: 3)
|
347
369
|
end
|
348
370
|
|
349
|
-
#
|
371
|
+
# Assert an experiment has been run with a given context.
|
350
372
|
assert_experiment_with(MyExperiment, context: { id: 1 })
|
351
373
|
|
352
|
-
#
|
374
|
+
# Assert that within the block, a matching experiment will be run.
|
353
375
|
assert_experiment_with(MyExperiment, variant: :red, context: { id: 4 }) do
|
354
376
|
MyExperiment.set(variant: :red).run(id: 4)
|
355
377
|
end
|
@@ -106,6 +106,11 @@ module ActiveExperiment
|
|
106
106
|
# will assign the first defined variant unless the provided methods are
|
107
107
|
# overridden.
|
108
108
|
class BaseRollout
|
109
|
+
# Convenience method to register the rollout with Active Experiment.
|
110
|
+
def self.register_as(name)
|
111
|
+
Rollouts.register(name, self)
|
112
|
+
end
|
113
|
+
|
109
114
|
def initialize(experiment_class, *args, **options, &block) # :nodoc:
|
110
115
|
@experiment_class = experiment_class
|
111
116
|
@rollout_args = args
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeexperiment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Jackson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|