abtest 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb40965c5504d6350cbf6bf7da5b76c9f0f47f6e
4
+ data.tar.gz: 978cf2b5d26878668c44e239d084da7aa87c30eb
5
+ SHA512:
6
+ metadata.gz: 1389a6c543d37030317a94a2f66a4158272403d92eed9ab7a44b658a10232ea2a4b9b7ff778541f5ca2dfd37e104e2dca76010f44ef657dc8064b926d7a3d435
7
+ data.tar.gz: 83d24beda283ba5afc6f03bfc869772c51b13ce045f2e24a717a3e11948331f4e4bb0f19e77b1ac6f47748734bc02d1fda060993168324957734e07bdde2dbfb
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "rails"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
23
25
  end
@@ -4,6 +4,5 @@ require "abtest/processor"
4
4
  require "abtest/registry"
5
5
  require "abtest/filters"
6
6
 
7
-
8
7
  module Abtest
9
8
  end
@@ -6,6 +6,7 @@ module Abtest
6
6
  Abtest.abtest_config.registered_tests.each do |test_hash|
7
7
  if (test_hash[:check].call(controller.request))
8
8
  controller.prepend_view_path(test_hash[:prefix])
9
+ test_hash[:process].call(controller) unless test_hash[:process].nil?
9
10
  end
10
11
  end
11
12
  end
@@ -2,6 +2,10 @@ require 'rails'
2
2
 
3
3
  module Abtest
4
4
  class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
7
+ end
8
+
5
9
  initializer "abtest.set_config", :after => 'bootstrap_hook' do
6
10
  config.abtest = ActiveSupport::OrderedOptions.new
7
11
  config.abtest.registered_tests = Set.new
@@ -1,15 +1,16 @@
1
1
  require "rails"
2
2
 
3
3
  module Abtest
4
- # Register a test. This method takes the view prefix of the directory
5
- # where your view overrides are located (most often the gem name) and a lambda
6
- # that will be used to determine whether or not to enable your test. The provided
7
- # lambda must return a truthy value for the test to be activated and accept a request object
8
- def self.register_test test_engine, lamb
9
- # Remove the default view path
10
- view_path = "#{test_engine.root}/app/views"
4
+ # Register a test. This method takes the following parameters:
5
+ # view_path: View prefix of the directory where your view overrides are located
6
+ # test: A lambda used to determine whether or not to activate this test. The provided
7
+ # lambda must return a truthy value for the test to be activated and accept a request object.
8
+ # process (optional): Lambda to run in the case of a test being activated. Will be passed the controller object.
9
+ def self.register_test(view_path, test, process = nil)
10
+ # If this path is already in the configured paths, remove it.
11
+ # This is used mainly for engine based tests.
11
12
  ActionController::Base.view_paths = ActionController::Base.view_paths.reject {|path| path.to_path == view_path }
12
- abtest_config.registered_tests.add({prefix: view_path, check: lamb})
13
+ abtest_config.registered_tests.add({prefix: view_path, check: test, process: process})
13
14
  end
14
15
 
15
16
  def self.abtest_config
@@ -0,0 +1,39 @@
1
+ namespace :abtest do
2
+ desc "Create a new experiment scaffold. Experiment name is a required arg. (rake abtest:add_experiment[name])"
3
+ task :add_experiment, [:name] => :environment do |t, args|
4
+ name = args[:name]
5
+ puts "Experiment name is required" and return if name.nil?
6
+
7
+ # Check to see if we have a tests directory
8
+ Dir.mkdir("#{Rails.root}/app/views/tests") unless Dir.exists?("#{Rails.root}/app/views/tests")
9
+
10
+ # Create a folder for this experiment
11
+ experiment_path = "#{Rails.root}/app/views/tests/#{args[:name]}"
12
+ Dir.mkdir(experiment_path) unless Dir.exists?(experiment_path)
13
+
14
+ # Create a new initializer file if it doesn't exist already
15
+ initializer_path = "#{Rails.root}/config/initializers/abtest.rb"
16
+ FileUtils.touch(initializer_path) unless File.exists?(initializer_path)
17
+
18
+ # Add template initializer
19
+ template = File.read("#{File.dirname(__FILE__)}/templates/initializer.erb")
20
+ renderer = ERB.new(template)
21
+ result = renderer.result(binding)
22
+
23
+ # Append initializer code to end of file
24
+ File.open(initializer_path, 'a') { |f| f.write(result) }
25
+
26
+ puts "Please edit #{initializer_path} to configure experiment."
27
+ end
28
+
29
+ desc "Delete all experiments"
30
+ task :delete_experiments => :environment do
31
+ # Remove tests directory
32
+ FileUtils.rm_rf("#{Rails.root}/app/views/tests") if Dir.exists?("#{Rails.root}/app/views/tests")
33
+
34
+ # Remove initializer
35
+ FileUtils.rm("#{Rails.root}/config/initializers/abtest.rb") if Dir.exists?("#{Rails.root}/config/initializers/abtest.rb")
36
+
37
+ puts "All tests removed"
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ <%= name %>_test = lambda { |request|
2
+ false
3
+ }
4
+
5
+ <%= name %>_process = lambda { |controller|
6
+
7
+ }
8
+
9
+ Abtest.register_test("<%= experiment_path %>", <%= name %>_test, <%= name %>_process)
@@ -1,3 +1,3 @@
1
1
  module Abtest
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,20 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abtest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steve Saarinen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2014-01-09 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
31
  - - ~>
20
32
  - !ruby/object:Gem::Version
@@ -22,7 +34,6 @@ dependencies:
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
38
  - - ~>
28
39
  - !ruby/object:Gem::Version
@@ -30,17 +41,15 @@ dependencies:
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  description: Railtie base to enable engine baset AB test modules
@@ -62,37 +71,32 @@ files:
62
71
  - lib/abtest/processor.rb
63
72
  - lib/abtest/railtie.rb
64
73
  - lib/abtest/registry.rb
74
+ - lib/abtest/tasks/experiments.rake
75
+ - lib/abtest/tasks/templates/initializer.erb
65
76
  - lib/abtest/version.rb
66
77
  homepage: http://www.whitepages.com
67
78
  licenses:
68
79
  - MIT
80
+ metadata: {}
69
81
  post_install_message:
70
82
  rdoc_options: []
71
83
  require_paths:
72
84
  - lib
73
85
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
86
  requirements:
76
- - - ! '>='
87
+ - - '>='
77
88
  - !ruby/object:Gem::Version
78
89
  version: '0'
79
- segments:
80
- - 0
81
- hash: -3468350091403392005
82
90
  required_rubygems_version: !ruby/object:Gem::Requirement
83
- none: false
84
91
  requirements:
85
- - - ! '>='
92
+ - - '>='
86
93
  - !ruby/object:Gem::Version
87
94
  version: '0'
88
- segments:
89
- - 0
90
- hash: -3468350091403392005
91
95
  requirements: []
92
96
  rubyforge_project:
93
- rubygems_version: 1.8.25
97
+ rubygems_version: 2.1.11
94
98
  signing_key:
95
- specification_version: 3
99
+ specification_version: 4
96
100
  summary: Manages registered AB test engines and provides before_filter to dynamically
97
101
  add load paths for enabled tests
98
102
  test_files: []