vignette 0.0.4pre2 → 0.0.5pre1
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.
- data/README.md +41 -2
- data/lib/vignette/object_extensions.rb +11 -20
- data/lib/vignette/version.rb +1 -1
- data/lib/vignette.rb +20 -8
- metadata +3 -2
data/README.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
# Vignette
|
2
2
|
|
3
|
-
|
3
|
+
Vignette makes it dead simple to run reliable A/b tests in your Rails project.
|
4
|
+
|
5
|
+
## Examples
|
6
|
+
|
7
|
+
Vignette is as simple as sampling from an Array:
|
8
|
+
|
9
|
+
@price = [5, 10, 15].vignette
|
10
|
+
|
11
|
+
We've also added a filter to HAML for testing:
|
12
|
+
|
13
|
+
%h1
|
14
|
+
:vignette
|
15
|
+
Welcome to the Zoo.
|
16
|
+
Come to see the Lions!
|
17
|
+
Don't get caught by a lemur!
|
4
18
|
|
5
19
|
## Installation
|
6
20
|
|
@@ -18,7 +32,32 @@ Or install it yourself as:
|
|
18
32
|
|
19
33
|
## Usage
|
20
34
|
|
21
|
-
|
35
|
+
Vignette was crafted to make A/b testing as simple as possible. Simply run the `vignette` function on any Array and get the result from a A/b test. Vignette will store this choice in session, a cookies or nowhere, based on how you configure Vignette. For this to work, all calls to Vignette must be within the request cycle (within an around_filter in ActionController::Base). Test are identified by a checksum of the Array, and thus, changing the Array will restart that test.
|
36
|
+
|
37
|
+
# To store in session (default)
|
38
|
+
Vignette.init(:session)
|
39
|
+
|
40
|
+
# To use cookies
|
41
|
+
Vignette.init(:cookies)
|
42
|
+
|
43
|
+
# Or random sampling
|
44
|
+
Vignette.init(:random)
|
45
|
+
|
46
|
+
Running tests:
|
47
|
+
|
48
|
+
[ 1,2,3 ].vignette # Chooses an option and stores test as indicated above
|
49
|
+
%w{one two three}.vignette # Same with strings
|
50
|
+
|
51
|
+
# or in HAML
|
52
|
+
|
53
|
+
:vignette
|
54
|
+
Test one
|
55
|
+
Test <strong>two</strong>
|
56
|
+
Test #{three}
|
57
|
+
|
58
|
+
Finally, to store in analytics which tests were run, simple check
|
59
|
+
|
60
|
+
Vignette.test -> { 'views/orders/new.html.haml:54d3c10a1b21' => 0 } # First choice was select for new.html.haml test
|
22
61
|
|
23
62
|
## Contributing
|
24
63
|
|
@@ -35,28 +35,19 @@ module ObjectExtensions
|
|
35
35
|
name
|
36
36
|
end
|
37
37
|
|
38
|
-
store =
|
39
|
-
|
40
|
-
raise VignetteError::ConfigError, "Missing cookies configuration in Vignette. Must access Vignette in controller within around_filter." if Vignette.cookies.nil?
|
41
|
-
Rails.logger.debug [ 'Vignette::vignette', 'Cookies Sampling', key, Vignette.cookies[key] ] if Vignette.logging
|
42
|
-
Vignette.cookies
|
43
|
-
when :session
|
44
|
-
raise VignetteError::ConfigError, "Missing session configuration in Vignette. Must access Vignette in controller within around_filter." if Vignette.session.nil?
|
45
|
-
Rails.logger.debug [ 'Vignette::vignette', 'Session Sampling', key, Vignette.session[key] ] if Vignette.logging
|
46
|
-
Vignette.session
|
47
|
-
else
|
48
|
-
Rails.logger.debug [ 'Vignette::vignette', 'Random Sampling' ] if Vignette.logging
|
49
|
-
{} # This is an empty storage
|
50
|
-
end
|
51
|
-
|
38
|
+
store = Vignette.get_store
|
39
|
+
|
52
40
|
choice = store[key] ||= rand(length) # Store key into storage if not available
|
53
|
-
|
54
|
-
# We're going to track all tests in request
|
55
|
-
Vignette.request[:vignette] ||= {}
|
56
|
-
Vignette.request[:vignette][:tests] ||= {}
|
57
|
-
Vignette.request[:vignette][:tests][test_name] = choice
|
41
|
+
result = self[choice.to_i]
|
58
42
|
|
59
|
-
|
43
|
+
# TODO: Make this clearer for how to store the test items
|
44
|
+
if Vignette.session
|
45
|
+
Vignette.session[:vignette] ||= {}
|
46
|
+
Vignette.session[:vignette][:tests] ||= {}
|
47
|
+
Vignette.session[:vignette][:tests][test_name] = result
|
48
|
+
end
|
49
|
+
|
50
|
+
return result
|
60
51
|
end
|
61
52
|
|
62
53
|
end
|
data/lib/vignette/version.rb
CHANGED
data/lib/vignette.rb
CHANGED
@@ -35,17 +35,29 @@ module Vignette
|
|
35
35
|
Vignette.session = session
|
36
36
|
Vignette.cookies = cookies
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def self.clear_request
|
40
40
|
Vignette.request = Vignette.session = Vignette.cookies = nil # clear items
|
41
41
|
end
|
42
|
-
|
43
|
-
def self.tests
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
Vignette.
|
42
|
+
|
43
|
+
def self.tests(session=Vignette.session)
|
44
|
+
session[:vignette] && session[:vignette][:tests] ? session[:vignette][:tests] : {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.get_store(session=Vignette.session, cookies=Vignette.cookies)
|
48
|
+
case Vignette.store
|
49
|
+
when :cookies
|
50
|
+
raise VignetteError::ConfigError, "Missing cookies configuration in Vignette. Must access Vignette in controller within around_filter." if cookies.nil?
|
51
|
+
Rails.logger.debug [ 'Vignette::vignette', 'Cookies Sampling', cookies ] if Vignette.logging
|
52
|
+
cookies
|
53
|
+
when :session
|
54
|
+
raise VignetteError::ConfigError, "Missing session configuration in Vignette. Must access Vignette in controller within around_filter." if session.nil?
|
55
|
+
Rails.logger.debug [ 'Vignette::vignette', 'Session Sampling', session ] if Vignette.logging
|
56
|
+
session
|
57
|
+
else
|
58
|
+
Rails.logger.debug [ 'Vignette::vignette', 'Random Sampling' ] if Vignette.logging
|
59
|
+
{} # This is an empty storage
|
60
|
+
end
|
49
61
|
end
|
50
62
|
|
51
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vignette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5pre1
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple, effective A/b testing made easy.
|
15
15
|
email:
|
@@ -54,3 +54,4 @@ signing_key:
|
|
54
54
|
specification_version: 3
|
55
55
|
summary: With a few simple features, get A/b testing up in your application.
|
56
56
|
test_files: []
|
57
|
+
has_rdoc:
|