abtest 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,8 @@ require "abtest/version"
2
2
  require "abtest/railtie"
3
3
  require "abtest/processor"
4
4
  require "abtest/registry"
5
+ require "abtest/filters"
6
+
5
7
 
6
8
  module Abtest
7
9
  end
@@ -0,0 +1,13 @@
1
+ module Abtest
2
+ module Filters
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ append_before_filter :process_abtests
7
+ end
8
+
9
+ def process_abtests
10
+ Abtest::Processor.process_tests(self)
11
+ end
12
+ end
13
+ end
@@ -1,9 +1,11 @@
1
+ require 'rails'
2
+
1
3
  module Abtest
2
4
  class Processor
3
- def self.process_tests
5
+ def self.process_tests controller
4
6
  Abtest.abtest_config.registered_tests.each do |test_hash|
5
- if (test_hash[:check])
6
- prepend_view_path(test_hash[:prefix])
7
+ if (test_hash[:check].call(controller.request))
8
+ controller.prepend_view_path(test_hash[:prefix])
7
9
  end
8
10
  end
9
11
  end
@@ -7,10 +7,9 @@ module Abtest
7
7
  config.abtest.registered_tests = Set.new
8
8
  end
9
9
 
10
- initializer "abtest.set_filter", :after => 'bootstrap_hook' do
11
- ActionController::Base.class_eval do
12
- include Abtest
13
- append_before_filter Abtest::Processor.process_tests
10
+ initializer "abtest.set_filter" do
11
+ ActiveSupport.on_load(:action_controller) do
12
+ ActionController::Base.send(:include, Abtest::Filters)
14
13
  end
15
14
  end
16
15
  end
@@ -1,10 +1,15 @@
1
+ require "rails"
2
+
1
3
  module Abtest
2
4
  # Register a test. This method takes the view prefix of the directory
3
5
  # where your view overrides are located (most often the gem name) and a lambda
4
6
  # that will be used to determine whether or not to enable your test. The provided
5
- # lambda must return a truthy value for the test to be activated.
6
- def self.register_test prefix, lamb
7
- abtest_config.registered_tests.add({prefix: prefix, check: lamb})
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"
11
+ 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})
8
13
  end
9
14
 
10
15
  def self.abtest_config
@@ -1,3 +1,3 @@
1
1
  module Abtest
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
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: 2014-01-07 00:00:00.000000000 Z
12
+ date: 2014-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -58,6 +58,7 @@ files:
58
58
  - Rakefile
59
59
  - abtest.gemspec
60
60
  - lib/abtest.rb
61
+ - lib/abtest/filters.rb
61
62
  - lib/abtest/processor.rb
62
63
  - lib/abtest/railtie.rb
63
64
  - lib/abtest/registry.rb
@@ -77,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  segments:
79
80
  - 0
80
- hash: 3168789410601359194
81
+ hash: -3468350091403392005
81
82
  required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  none: false
83
84
  requirements:
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  version: '0'
87
88
  segments:
88
89
  - 0
89
- hash: 3168789410601359194
90
+ hash: -3468350091403392005
90
91
  requirements: []
91
92
  rubyforge_project:
92
93
  rubygems_version: 1.8.25