abtest 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/abtest.rb +0 -1
- data/lib/abtest/filters.rb +43 -1
- data/lib/abtest/railtie.rb +7 -7
- data/lib/abtest/tasks/experiments.rake +31 -3
- data/lib/abtest/tasks/templates/initializer.erb +20 -14
- data/lib/abtest/version.rb +1 -1
- metadata +3 -4
- data/lib/abtest/processor.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4158fd4b6a530de6b5e353dd69aa61ef04c2f19c
|
4
|
+
data.tar.gz: 6bce19ab1385172c96192d408c3f85cd498a11ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1299386c8972fc29df0e07c42041354eecc14399eb211683de867051cb11ae65ad0604b8f1a522ae6c1c3c274f2ac0c414e2088116e3fa7cc33e91feb10f8e58
|
7
|
+
data.tar.gz: 75847dd2c20be03b18ba16e8f8f051b0b32b58325c2d430d0d49422669d61225047274ea223cde38f0a63702982bbae6b8481dc446215215139c6564623b03c1
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
A-B testing framework and manager for Rails. This gem allows the addition of experiments that change view code and assets
|
4
4
|
based on the results of a simple test proc.
|
5
5
|
|
6
|
-
This gem modifies ActionView::Base as well as the global assets environment to enable overrides in the experiments directory to
|
6
|
+
This gem modifies ActionView::Base as well as the global assets environment to enable overrides in the experiments directory to
|
7
7
|
take effect.
|
8
8
|
|
9
9
|
## Installation
|
@@ -22,10 +22,14 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
Once the gem is installed in your Rails application,
|
25
|
+
Once the gem is installed in your Rails application, you can run the following command to set up an experiment:
|
26
26
|
|
27
27
|
$ bundle exec rake abtest:add_experiment[experiment_name]
|
28
28
|
|
29
|
+
To delete an experiment, run the following command:
|
30
|
+
|
31
|
+
$ bundle exec rake abtest:delete_experiment[experiment_name]
|
32
|
+
|
29
33
|
To remove all experiments, run the following command:
|
30
34
|
|
31
35
|
$ bundle exec rake abtest:delete_experiments
|
data/lib/abtest.rb
CHANGED
data/lib/abtest/filters.rb
CHANGED
@@ -7,7 +7,49 @@ module Abtest
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def process_abtests
|
10
|
-
|
10
|
+
experiment_activated = false
|
11
|
+
|
12
|
+
Abtest.abtest_config.registered_tests.each do |test_hash|
|
13
|
+
app_config = Rails.application.config
|
14
|
+
environment = Rails.application.assets
|
15
|
+
experiment_name = test_hash[:name]
|
16
|
+
experiment_path = Rails.root.join('abtest', 'experiments', experiment_name)
|
17
|
+
|
18
|
+
if (test_hash[:check].call(request) && !experiment_activated)
|
19
|
+
# ensure experimental translations are loaded
|
20
|
+
unless (I18n.load_path || []).last.include?(experiment_name)
|
21
|
+
I18n.load_path = app_config.i18n.load_path + Dir[Rails.root.join('abtest', 'experiments', experiment_name, 'config', 'locales', '*.{rb,yml}').to_s]
|
22
|
+
I18n.reload!
|
23
|
+
end
|
24
|
+
|
25
|
+
manifest = Abtest::ManifestManager.instance.retrieve_manifest(experiment_name)
|
26
|
+
|
27
|
+
# Set view context for asset path
|
28
|
+
view_context_class.assets_prefix = File.join(app_config.assets.prefix, 'experiments', experiment_name)
|
29
|
+
view_context_class.assets_environment = manifest.environment
|
30
|
+
view_context_class.assets_manifest = manifest
|
31
|
+
|
32
|
+
# Prepend the lookup paths for our views
|
33
|
+
prepend_view_path(File.join(experiment_path, 'views'))
|
34
|
+
|
35
|
+
test_hash[:process].call(binding) unless test_hash[:process].nil?
|
36
|
+
|
37
|
+
experiment_activated = true
|
38
|
+
elsif (!experiment_activated)
|
39
|
+
# ensure experimental translations are removed
|
40
|
+
I18n.reload! if I18n.load_path.reject! { |path| path.include?(experiment_name) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
unless experiment_activated
|
45
|
+
# Use default manifest
|
46
|
+
manifest = Abtest::ManifestManager.instance.retrieve_manifest('default')
|
47
|
+
|
48
|
+
# Set view context for asset path
|
49
|
+
view_context_class.assets_prefix = File.join(Rails.application.config.assets.prefix)
|
50
|
+
view_context_class.assets_environment = manifest.environment
|
51
|
+
view_context_class.assets_manifest = manifest
|
52
|
+
end
|
11
53
|
end
|
12
54
|
end
|
13
55
|
end
|
data/lib/abtest/railtie.rb
CHANGED
@@ -23,15 +23,15 @@ module Abtest
|
|
23
23
|
end
|
24
24
|
|
25
25
|
module ActionView
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
module Rendering
|
27
|
+
module ClassMethods
|
28
|
+
def view_context
|
29
|
+
view_context_class.new(view_renderer, view_assigns, self)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
37
|
|
@@ -16,11 +16,13 @@ namespace :abtest do
|
|
16
16
|
images_path = File.join(experiment_path, app_config.assets.prefix, 'images')
|
17
17
|
javascript_path = File.join(experiment_path, app_config.assets.prefix, 'javascripts')
|
18
18
|
view_path = File.join(experiment_path, 'views')
|
19
|
+
experiment_init_path = File.join(Rails.root, 'config', 'initializers', 'abtest')
|
19
20
|
|
20
21
|
FileUtils.mkdir_p(view_path)
|
21
22
|
FileUtils.mkdir_p(application_css_path)
|
22
23
|
FileUtils.mkdir_p(images_path)
|
23
24
|
FileUtils.mkdir_p(javascript_path)
|
25
|
+
FileUtils.mkdir_p(experiment_init_path)
|
24
26
|
|
25
27
|
# Create a new initializer file if it doesn't exist already
|
26
28
|
initializer_path = File.join(Rails.root, 'config', 'initializers', 'abtest.rb')
|
@@ -36,20 +38,46 @@ namespace :abtest do
|
|
36
38
|
renderer = ERB.new(template)
|
37
39
|
result = renderer.result(binding)
|
38
40
|
|
39
|
-
#
|
40
|
-
File.
|
41
|
+
# Create new initializer file
|
42
|
+
init_file_path = File.join(experiment_init_path, "#{name}.rb")
|
43
|
+
File.open(init_file_path, 'a') { |f| f.write(result) }
|
41
44
|
|
42
|
-
puts "Please edit #{
|
45
|
+
puts "Please edit #{init_file_path} to configure experiment."
|
43
46
|
end
|
44
47
|
|
45
48
|
desc "Delete all experiments"
|
46
49
|
task :delete_experiments => :environment do
|
47
50
|
# Remove experiments directory
|
48
51
|
FileUtils.rm_rf(File.join(Rails.root, 'abtest'))
|
52
|
+
FileUtils.rm_rf(File.join(Rails.root, 'config', 'initializers', 'abtest'))
|
49
53
|
|
50
54
|
# Remove initializer
|
51
55
|
FileUtils.rm_f(File.join(Rails.root, 'config', 'initializers', 'abtest.rb'))
|
52
56
|
|
53
57
|
puts "All tests removed"
|
54
58
|
end
|
59
|
+
|
60
|
+
desc "Delete experiment. Experiment name is a required arg. (rake abtest:delete_experiment[name])"
|
61
|
+
task :delete_experiment, [:name] => :environment do |t, args|
|
62
|
+
name = args[:name]
|
63
|
+
|
64
|
+
if (name.nil? || name.blank?)
|
65
|
+
puts "Experiment name is required. Usage: rake abtest:add_experiment[name]"
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
test_root = File.join(Rails.root, 'abtest')
|
70
|
+
experiment_path = File.join(test_root, 'experiments', name)
|
71
|
+
experiment_init_path = File.join(Rails.root, 'config', 'initializers', 'abtest')
|
72
|
+
init_file_path = File.join(experiment_init_path, "#{name}.rb")
|
73
|
+
|
74
|
+
# Remove experiments directory
|
75
|
+
FileUtils.rm_rf(experiment_path)
|
76
|
+
|
77
|
+
# Remove initializer
|
78
|
+
FileUtils.rm_f(init_file_path)
|
79
|
+
|
80
|
+
puts "Experiment #{name} removed."
|
81
|
+
end
|
82
|
+
|
55
83
|
end
|
@@ -1,25 +1,31 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
##########################################################
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# Configuration for <%= name %> experiment.
|
5
5
|
#
|
6
|
-
|
6
|
+
# The <%= name %>_test lambda is used to determine
|
7
|
+
# whether or not to activate this experiment. It
|
8
|
+
# is passed the current request.
|
9
|
+
#
|
10
|
+
# You can optionally add any controller processing
|
11
|
+
# that would be acceptable in a before filter by
|
12
|
+
# using the <%= name %>_process lambda. The processor
|
13
|
+
# is passed a binding of the context within a controller
|
14
|
+
# before_filter.
|
15
|
+
#
|
16
|
+
###########################################################
|
7
17
|
|
8
|
-
<%= name %>_test = lambda { |request|
|
9
|
-
false
|
18
|
+
<%= name %>_test = lambda { |request|
|
19
|
+
false
|
10
20
|
}
|
11
21
|
|
12
|
-
|
13
|
-
|
22
|
+
# The processor is passed a binding of the context within a controller
|
23
|
+
# before_filter.
|
24
|
+
<%= name %>_process = lambda { |controller_context_binding|
|
25
|
+
|
14
26
|
}
|
15
27
|
|
16
28
|
Abtest.register_test("<%= name %>", <%= name %>_test, <%= name %>_process)
|
17
29
|
|
18
30
|
# Add additional files to precompile here
|
19
|
-
Rails.application.config.abtest.precompile_assets
|
20
|
-
|
21
|
-
################################################
|
22
|
-
#
|
23
|
-
# End configuration for <%= name %> experiment
|
24
|
-
#
|
25
|
-
################################################
|
31
|
+
Rails.application.config.abtest.precompile_assets += []
|
data/lib/abtest/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abtest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Saarinen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-12-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -86,7 +86,6 @@ files:
|
|
86
86
|
- lib/abtest/asset.rb
|
87
87
|
- lib/abtest/asset_task.rb
|
88
88
|
- lib/abtest/filters.rb
|
89
|
-
- lib/abtest/processor.rb
|
90
89
|
- lib/abtest/railtie.rb
|
91
90
|
- lib/abtest/registry.rb
|
92
91
|
- lib/abtest/tasks/asset_precompile.rake
|
@@ -114,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
113
|
version: '0'
|
115
114
|
requirements: []
|
116
115
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.4.3
|
118
117
|
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
summary: Manages AB experiments and allows for view and asset context switching for
|
data/lib/abtest/processor.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
|
3
|
-
module Abtest
|
4
|
-
class Processor
|
5
|
-
def self.process_tests controller
|
6
|
-
|
7
|
-
experiment_activated = false
|
8
|
-
|
9
|
-
Abtest.abtest_config.registered_tests.each do |test_hash|
|
10
|
-
app_config = Rails.application.config
|
11
|
-
environment = Rails.application.assets
|
12
|
-
experiment_name = test_hash[:name]
|
13
|
-
experiment_path = Rails.root.join('abtest', 'experiments', experiment_name)
|
14
|
-
|
15
|
-
if (test_hash[:check].call(controller.request) && !experiment_activated)
|
16
|
-
# ensure experimental translations are loaded
|
17
|
-
unless (I18n.load_path || []).last.include?(experiment_name)
|
18
|
-
I18n.load_path = app_config.i18n.load_path + Dir[Rails.root.join('abtest', 'experiments', experiment_name, 'config', 'locales', '*.{rb,yml}').to_s]
|
19
|
-
I18n.reload!
|
20
|
-
end
|
21
|
-
|
22
|
-
manifest = Abtest::ManifestManager.instance.retrieve_manifest(experiment_name)
|
23
|
-
|
24
|
-
# Set view context for asset path
|
25
|
-
controller.view_context_class.assets_prefix = File.join(app_config.assets.prefix, 'experiments', experiment_name)
|
26
|
-
controller.view_context_class.assets_environment = manifest.environment
|
27
|
-
controller.view_context_class.assets_manifest = manifest
|
28
|
-
|
29
|
-
# Prepend the lookup paths for our views
|
30
|
-
controller.prepend_view_path(File.join(experiment_path, 'views'))
|
31
|
-
|
32
|
-
test_hash[:process].call(controller) unless test_hash[:process].nil?
|
33
|
-
|
34
|
-
experiment_activated = true
|
35
|
-
elsif (!experiment_activated)
|
36
|
-
# ensure experimental translations are removed
|
37
|
-
I18n.reload! if I18n.load_path.reject! { |path| path.include?(experiment_name) }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
unless experiment_activated
|
42
|
-
# Use default manifest
|
43
|
-
manifest = Abtest::ManifestManager.instance.retrieve_manifest('default')
|
44
|
-
|
45
|
-
# Set view context for asset path
|
46
|
-
controller.view_context_class.assets_prefix = File.join(Rails.application.config.assets.prefix)
|
47
|
-
controller.view_context_class.assets_environment = manifest.environment
|
48
|
-
controller.view_context_class.assets_manifest = manifest
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|