vanity 1.2.0 → 1.3.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.
- data/CHANGELOG +34 -0
- data/Gemfile +16 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +10 -5
- data/Rakefile +119 -0
- data/bin/vanity +23 -18
- data/lib/vanity.rb +12 -4
- data/lib/vanity/commands.rb +1 -0
- data/lib/vanity/commands/list.rb +21 -0
- data/lib/vanity/experiment/ab_test.rb +8 -1
- data/lib/vanity/experiment/base.rb +40 -30
- data/lib/vanity/frameworks/rails.rb +222 -0
- data/lib/vanity/metric/active_record.rb +77 -0
- data/lib/vanity/{metric.rb → metric/base.rb} +6 -71
- data/lib/vanity/metric/google_analytics.rb +76 -0
- data/lib/vanity/playground.rb +93 -44
- data/lib/vanity/templates/_metric.erb +12 -7
- data/lib/vanity/templates/vanity.css +1 -0
- data/test/ab_test_test.rb +69 -48
- data/test/experiment_test.rb +29 -15
- data/test/metric_test.rb +104 -0
- data/test/myapp/app/controllers/application_controller.rb +2 -0
- data/test/myapp/app/controllers/main_controller.rb +7 -0
- data/test/myapp/config/boot.rb +110 -0
- data/test/myapp/config/environment.rb +10 -0
- data/test/myapp/config/environments/production.rb +0 -0
- data/test/myapp/config/routes.rb +3 -0
- data/test/myapp/log/production.log +80 -0
- data/test/passenger_test.rb +34 -0
- data/test/rails_test.rb +129 -1
- data/test/test_helper.rb +12 -4
- data/vanity.gemspec +2 -2
- data/vendor/cache/RedCloth-4.2.2.gem +0 -0
- data/vendor/cache/actionmailer-2.3.5.gem +0 -0
- data/vendor/cache/actionpack-2.3.5.gem +0 -0
- data/vendor/cache/activerecord-2.3.5.gem +0 -0
- data/vendor/cache/activeresource-2.3.5.gem +0 -0
- data/vendor/cache/activesupport-2.3.5.gem +0 -0
- data/vendor/cache/autotest-4.2.7.gem +0 -0
- data/vendor/cache/autotest-fsevent-0.2.1.gem +0 -0
- data/vendor/cache/autotest-growl-0.2.0.gem +0 -0
- data/vendor/cache/bundler-0.9.7.gem +0 -0
- data/vendor/cache/classifier-1.3.1.gem +0 -0
- data/vendor/cache/directory_watcher-1.3.1.gem +0 -0
- data/vendor/cache/fastthread-1.0.7.gem +0 -0
- data/vendor/cache/garb-0.7.0.gem +0 -0
- data/vendor/cache/happymapper-0.3.0.gem +0 -0
- data/vendor/cache/jekyll-0.5.7.gem +0 -0
- data/vendor/cache/libxml-ruby-1.1.3.gem +0 -0
- data/vendor/cache/liquid-2.0.0.gem +0 -0
- data/vendor/cache/maruku-0.6.0.gem +0 -0
- data/vendor/cache/mocha-0.9.8.gem +0 -0
- data/vendor/cache/open4-1.0.1.gem +0 -0
- data/vendor/cache/passenger-2.2.9.gem +0 -0
- data/vendor/cache/rack-1.0.1.gem +0 -0
- data/vendor/cache/rails-2.3.5.gem +0 -0
- data/vendor/cache/rake-0.8.7.gem +0 -0
- data/vendor/cache/rubygems-update-1.3.5.gem +0 -0
- data/vendor/cache/shoulda-2.10.3.gem +0 -0
- data/vendor/cache/sqlite3-ruby-1.2.5.gem +0 -0
- data/vendor/cache/stemmer-1.0.1.gem +0 -0
- data/vendor/cache/syntax-1.0.0.gem +0 -0
- data/vendor/cache/sys-uname-0.8.4.gem +0 -0
- data/vendor/cache/timecop-0.3.4.gem +0 -0
- metadata +60 -11
- data/lib/vanity/rails.rb +0 -22
- data/lib/vanity/rails/dashboard.rb +0 -24
- data/lib/vanity/rails/helpers.rb +0 -101
- data/lib/vanity/rails/testing.rb +0 -11
data/lib/vanity/rails/helpers.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
module Vanity
|
2
|
-
# Helper methods for use in your controllers.
|
3
|
-
#
|
4
|
-
# 1) Use Vanity from within your controller:
|
5
|
-
#
|
6
|
-
# class ApplicationController < ActionController::Base
|
7
|
-
# use_vanity :current_user end
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# 2) Present different options for an A/B test:
|
11
|
-
#
|
12
|
-
# Get started for only $<%= ab_test :pricing %> a month!
|
13
|
-
#
|
14
|
-
# 3) Measure conversion:
|
15
|
-
#
|
16
|
-
# def signup
|
17
|
-
# track! :pricing
|
18
|
-
# . . .
|
19
|
-
# end
|
20
|
-
module Rails
|
21
|
-
module ClassMethods
|
22
|
-
|
23
|
-
# Defines the vanity_identity method and the set_identity_context filter.
|
24
|
-
#
|
25
|
-
# Call with the name of a method that returns an object whose identity
|
26
|
-
# will be used as the Vanity identity. Confusing? Let's try by example:
|
27
|
-
#
|
28
|
-
# class ApplicationController < ActionController::Base
|
29
|
-
# use_vanity :current_user
|
30
|
-
#
|
31
|
-
# def current_user
|
32
|
-
# User.find(session[:user_id])
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# If that method (current_user in this example) returns nil, Vanity will
|
37
|
-
# set the identity for you (using a cookie to remember it across
|
38
|
-
# requests). It also uses this mechanism if you don't provide an
|
39
|
-
# identity object, by calling use_vanity with no arguments.
|
40
|
-
#
|
41
|
-
# Of course you can also use a block:
|
42
|
-
# class ProjectController < ApplicationController
|
43
|
-
# use_vanity { |controller| controller.params[:project_id] }
|
44
|
-
# end
|
45
|
-
def use_vanity(symbol = nil, &block)
|
46
|
-
define_method :vanity_identity do
|
47
|
-
return @vanity_identity if @vanity_identity
|
48
|
-
if block
|
49
|
-
@vanity_identity = block.call(self)
|
50
|
-
elsif symbol && object = send(symbol)
|
51
|
-
@vanity_identity = object.id
|
52
|
-
elsif response # everyday use
|
53
|
-
@vanity_identity = cookies["vanity_id"] || ActiveSupport::SecureRandom.hex(16)
|
54
|
-
cookies["vanity_id"] = { :value=>@vanity_identity, :expires=>1.month.from_now }
|
55
|
-
@vanity_identity
|
56
|
-
else # during functional testing
|
57
|
-
@vanity_identity = "test"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
define_method :set_vanity_context do
|
61
|
-
Vanity.context = self
|
62
|
-
end
|
63
|
-
before_filter :set_vanity_context
|
64
|
-
before_filter { Vanity.playground.reload! } unless ::Rails.configuration.cache_classes
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# This method returns one of the alternative values in the named A/B test.
|
69
|
-
#
|
70
|
-
# @example A/B two alternatives for a page
|
71
|
-
# def index
|
72
|
-
# if ab_test(:new_page) # true/false test
|
73
|
-
# render action: "new_page"
|
74
|
-
# else
|
75
|
-
# render action: "index"
|
76
|
-
# end
|
77
|
-
# end
|
78
|
-
# @example Similar, alternative value is page name
|
79
|
-
# def index
|
80
|
-
# render action: ab_test(:new_page)
|
81
|
-
# end
|
82
|
-
# @example A/B test inside ERB template (condition)
|
83
|
-
# <%= if ab_test(:banner) %>100% less complexity!<% end %>
|
84
|
-
# @example A/B test inside ERB template (value)
|
85
|
-
# <%= ab_test(:greeting) %> <%= current_user.name %>
|
86
|
-
# @example A/B test inside ERB template (capture)
|
87
|
-
# <% ab_test :features do |count| %>
|
88
|
-
# <%= count %> features to choose from!
|
89
|
-
# <% end %>
|
90
|
-
def ab_test(name, &block)
|
91
|
-
value = Vanity.playground.experiment(name).choose
|
92
|
-
if block
|
93
|
-
content = capture(value, &block)
|
94
|
-
block_called_from_erb?(block) ? concat(content) : content
|
95
|
-
else
|
96
|
-
value
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
data/lib/vanity/rails/testing.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module ActionController
|
2
|
-
class TestCase
|
3
|
-
alias :setup_controller_request_and_response_without_vanity :setup_controller_request_and_response
|
4
|
-
# Sets Vanity.context to the current controller, so you can do things like:
|
5
|
-
# experiment(:simple).chooses(:green)
|
6
|
-
def setup_controller_request_and_response
|
7
|
-
setup_controller_request_and_response_without_vanity
|
8
|
-
Vanity.context = @controller
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|