crabby 0.0.2

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.
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # Saber - The Simple A/B Experiment Renderer
2
+
3
+ ## What is Saber?
4
+
5
+ Saber provides a very thin layer for organizing and displaying a/b or "split"
6
+ test experiments. It is designed to facilitate a/b testing of site designs,
7
+ experiences and workflows, but is meant as a lightweight alternatives to other
8
+ a/b test frameworks.
9
+
10
+ Split is not a full-featured framework. It has one role, which is to provide a
11
+ simple DSL for displaying variations in a/b exeperiments. It is not responsible
12
+ for recording those experiments. In this way we avoid coupling to specific
13
+ database implementations.
14
+
15
+ There are many, many very good analytics tools and frameworks out there, and
16
+ we feel those are going to be the best suited to recording and analyzing the
17
+ results of a/b experiments.
18
+
19
+ ## How to use Saber
20
+
21
+ ### In the Controllers
22
+
23
+ Saber adds a simple helper method to setup an A/B experiment to your controllers
24
+
25
+ For example to setup an A/B test with three variants and equal weighting:
26
+
27
+ ```ruby
28
+ def index
29
+ setup_ab_test_parameters ['v1', 'v2', 'v3']
30
+ end
31
+ ```
32
+
33
+ If some non-uniform weighting is desired simply use a Hash
34
+
35
+ ```ruby
36
+ def index
37
+ setup_ab_test_parameters { v1: 1, v2: 3, v3:1 }
38
+ end
39
+ ```
40
+
41
+ In the above example 'v2' is 3 times more likely than v1 or v3 to be shown. The
42
+ weighting can be any numbers including floats, or percent values, they are
43
+ simply used relative to their total.
44
+
45
+ ### In the Views
46
+
47
+ Saber simply sets a parameter called `@ab_version` which is available in the
48
+ view. However a much nicer handy view helper is provided in stead. The
49
+ recommended usage is:
50
+
51
+ ```haml
52
+ -if ab_version(:v1)
53
+ -# v1 specific view content goes here
54
+ -elsif ab_version(:v2)
55
+ -# v2 specific view content goes here
56
+ ```
57
+
58
+ There are a number of ways you can organize content for A/B tests which is why
59
+ Saber takes no opinions on this matter. Depending on the type of A/B test the
60
+ approach you may want to take can vary greatly.
61
+
62
+ If the content between tests varies greatly then I recommend using a seperate
63
+ partial for each test and then use the view helper to add the conditional logic
64
+ to decide which partial to render.
65
+
66
+ If the content differences are small then just sprinkle where needed.
67
+
68
+ ### Ensuring consistent testing using `session` variables
69
+
70
+ Saber stores a session value in `session[:page_version]` with the name of the
71
+ ab-test version. It ensures that repeated views by the same person show the same
72
+ page (showing a different page each time would be strange and also probably
73
+ invalidate you a/b test results somewhat).
74
+
75
+ ### Overriding Saber
76
+
77
+ Saber can also be overidden as needed by passing a query parameter like
78
+ `?page_version=v2`. This will skip the random selection (or the current session
79
+ parameter) and show the 'v2' page every time (it also sets
80
+ `session[:page_version]` to 'v2' for convenience).
81
+
82
+ ### Where are the Analytics?
83
+
84
+ There are so many great analytics platforms out there for collecting a/b testing
85
+ metrics that do a better job than I (or most people) could hope to achieve with
86
+ a simple gem.
87
+
88
+ This means you are free to analyse your a/b test results with any one you choose
89
+ (I like [Mixpanel][mp] myself). Saber may provide some integration helpers for
90
+ these services in the future (pull requests accepted).
91
+
92
+ If you really want to host your analytics then [Split][split] is probably much
93
+ better suited to your needs.
94
+
95
+ This projectd uses the MIT-LICENSE.
96
+
97
+ [mp]: http://mixpanel.com
98
+ [split]: https://github.com/andrew/split
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Saber'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rspec/core/rake_task'
26
+
27
+ desc 'Default: run specs.'
28
+ task :default => :spec
29
+
30
+ desc "Run specs"
31
+ RSpec::Core::RakeTask.new do |t|
32
+ end
@@ -0,0 +1 @@
1
+ require 'crabby/railtie' if defined?(Rails)
@@ -0,0 +1,34 @@
1
+ module Crabby
2
+ module ControllerHelper
3
+ private
4
+ # Helps with rendering a simple a/b test by setting a page page_version variable
5
+ def setup_ab_test_parameters values
6
+ versions = {}
7
+ if values.is_a? Array
8
+ values.each { |v| versions[v] = 1 }
9
+ elsif values.is_a? Hash
10
+ versions = values
11
+ else
12
+ raise "Must pass either a weighted hash or an array of versions to use"
13
+ end
14
+ set_version params[:page_version] if versions.keys.any? { |k| k.to_s == params[:page_version].to_s }
15
+ set_version(session[:page_version]) if not @ab_version and versions.keys.any? { |k| k.to_s == session[:page_version].to_s }
16
+ set_random_version(versions) unless @ab_version
17
+ end
18
+
19
+ def set_random_version versions
20
+ total = versions.values.inject(:+).to_f
21
+ roll = Random.rand(total)
22
+ sum = 0.0
23
+ version = versions.find do |k,v|
24
+ sum = sum + v
25
+ roll <= sum
26
+ end
27
+ session[:page_version] = @ab_version = version[0].to_s
28
+ end
29
+
30
+ def set_version version
31
+ session[:page_version] = @ab_version = version.to_s
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ require 'crabby/view_helper'
2
+ require 'crabby/controller_helper'
3
+ module Crabby
4
+ class Railtie < Rails::Railtie
5
+ initializer "crabby.view_helper" do
6
+ ActionView::Base.send :include, ViewHelper
7
+ end
8
+ initializer "crabby.controller_helper" do
9
+ ActionController::Base.send :include, ControllerHelper
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Crabby
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,7 @@
1
+ module Crabby
2
+ module ViewHelper
3
+ def ab_version? name
4
+ return name.to_s == @ab_version
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crabby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Nicola
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Provides some utility functions for controllers and views that make running
63
+ a/b tests a breeze.
64
+ email:
65
+ - chnicola@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - lib/crabby/controller_helper.rb
71
+ - lib/crabby/railtie.rb
72
+ - lib/crabby/version.rb
73
+ - lib/crabby/view_helper.rb
74
+ - lib/crabby.rb
75
+ - MIT-LICENSE
76
+ - Rakefile
77
+ - README.md
78
+ homepage: https://github.com/lucisferre/crabby
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.18
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Compact rails A/B testing utilities
102
+ test_files: []