vanity 2.0.0.beta8 → 2.0.0.beta9
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/.travis.yml +4 -2
- data/Appraisals +1 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +4 -1
- data/gemfiles/rails32.gemfile +3 -2
- data/gemfiles/rails32.gemfile.lock +4 -5
- data/gemfiles/rails4.gemfile +2 -1
- data/gemfiles/rails4.gemfile.lock +3 -1
- data/gemfiles/rails41.gemfile +2 -1
- data/gemfiles/rails41.gemfile.lock +3 -1
- data/gemfiles/rails42.gemfile +2 -1
- data/gemfiles/rails42.gemfile.lock +3 -1
- data/lib/vanity.rb +11 -5
- data/lib/vanity/adapters.rb +20 -0
- data/lib/vanity/adapters/abstract_adapter.rb +0 -18
- data/lib/vanity/autoconnect.rb +1 -0
- data/lib/vanity/configuration.rb +211 -0
- data/lib/vanity/connection.rb +100 -0
- data/lib/vanity/frameworks.rb +2 -0
- data/lib/vanity/frameworks/rails.rb +7 -5
- data/lib/vanity/helpers.rb +1 -0
- data/{config → lib/vanity}/locales/vanity.en.yml +0 -0
- data/{config → lib/vanity}/locales/vanity.pt-BR.yml +0 -0
- data/lib/vanity/playground.rb +138 -338
- data/lib/vanity/vanity.rb +166 -0
- data/lib/vanity/version.rb +1 -1
- data/test/configuration_test.rb +90 -0
- data/test/connection_test.rb +46 -0
- data/test/data/redis.yml.url +2 -0
- data/test/data/vanity.yml.activerecord +6 -0
- data/test/data/vanity.yml.mock +4 -0
- data/test/data/vanity.yml.redis +5 -0
- data/test/data/vanity.yml.redis-erb +3 -0
- data/test/experiment/ab_test.rb +1 -1
- data/test/experiment/base_test.rb +1 -1
- data/test/frameworks/rails/rails_test.rb +34 -30
- data/test/metric/remote_test.rb +8 -8
- data/test/playground_test.rb +1 -27
- data/test/templates_test.rb +3 -2
- data/test/test_helper.rb +24 -12
- data/test/vanity_test.rb +130 -0
- metadata +25 -5
data/.travis.yml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
sudo: false
|
2
2
|
cache: bundler
|
3
3
|
language: ruby
|
4
|
+
before_script:
|
5
|
+
- 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc' # skip installing docs for gems
|
6
|
+
before_install:
|
7
|
+
- gem install bundler -v="1.8.0" # Minimum version of bundler required
|
4
8
|
bundler_args: --without development
|
5
9
|
script: 'bundle exec rake test'
|
6
10
|
services:
|
@@ -21,5 +25,3 @@ gemfile:
|
|
21
25
|
- gemfiles/rails4.gemfile
|
22
26
|
- gemfiles/rails41.gemfile
|
23
27
|
- gemfiles/rails42.gemfile
|
24
|
-
before_script:
|
25
|
-
- 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc' # skip installing docs for gems
|
data/Appraisals
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
appraise "rails32" do
|
2
2
|
gem "mocha", "~> 1.0", :require=>false
|
3
3
|
gem "minitest", "~>4.2.0"
|
4
|
-
gem "test-unit", "~> 3.0"
|
5
4
|
gem "rails", "3.2.22"
|
5
|
+
gem "minitest_tu_shim", "~> 1.3.3", :platforms => :mri_22
|
6
6
|
gem "fastthread", :git => "git://github.com/zoltankiss/fastthread.git", :platforms => :mri_20
|
7
7
|
gem "passenger", "~>3.0"
|
8
8
|
end
|
data/Gemfile
CHANGED
@@ -14,11 +14,12 @@ gem "integration", "<= 0.1.0"
|
|
14
14
|
gem "rubystats"
|
15
15
|
|
16
16
|
# APIs
|
17
|
-
gem "garb", "< 0.9.2" # API changes at this version
|
17
|
+
gem "garb", "< 0.9.2", :require => false # API changes at this version
|
18
18
|
|
19
19
|
# Testing
|
20
20
|
gem "timecop", :require=>false
|
21
21
|
gem "webmock", :require=>false
|
22
|
+
gem "fakefs", :require => "fakefs/safe"
|
22
23
|
|
23
24
|
platform :ruby do
|
24
25
|
gem "bson_ext"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vanity (2.0.0.
|
4
|
+
vanity (2.0.0.beta9)
|
5
5
|
i18n
|
6
6
|
|
7
7
|
GEM
|
@@ -34,8 +34,10 @@ GEM
|
|
34
34
|
coffee-script-source (1.9.1)
|
35
35
|
colorator (0.1)
|
36
36
|
crack (0.3.1)
|
37
|
+
directory_watcher (1.4.1)
|
37
38
|
execjs (2.5.2)
|
38
39
|
fast-stemmer (1.0.2)
|
40
|
+
fakefs (0.6.7)
|
39
41
|
ffi (1.9.8)
|
40
42
|
garb (0.9.1)
|
41
43
|
activesupport (>= 2.2.0)
|
@@ -118,6 +120,7 @@ DEPENDENCIES
|
|
118
120
|
appraisal (~> 1.0.2)
|
119
121
|
bson_ext
|
120
122
|
bundler (>= 1.0.0)
|
123
|
+
fakefs
|
121
124
|
garb (< 0.9.2)
|
122
125
|
integration (<= 0.1.0)
|
123
126
|
jdbc-sqlite3
|
data/gemfiles/rails32.gemfile
CHANGED
@@ -8,13 +8,14 @@ gem "redis-namespace", ">= 1.1.0"
|
|
8
8
|
gem "mongo"
|
9
9
|
gem "integration", "<= 0.1.0"
|
10
10
|
gem "rubystats"
|
11
|
-
gem "garb", "< 0.9.2"
|
11
|
+
gem "garb", "< 0.9.2", :require=>false
|
12
12
|
gem "timecop", :require => false
|
13
13
|
gem "webmock", :require => false
|
14
14
|
gem "mocha", "~> 1.0", :require => false
|
15
|
+
gem "fakefs", :require=>"fakefs/safe"
|
15
16
|
gem "minitest", "~>4.2.0"
|
16
|
-
gem "test-unit", "~> 3.0"
|
17
17
|
gem "rails", "3.2.22"
|
18
|
+
gem "minitest_tu_shim", "~> 1.3.3", :platforms => :mri_22
|
18
19
|
gem "fastthread", :git => "git://github.com/zoltankiss/fastthread.git", :platforms => :mri_20
|
19
20
|
gem "passenger", "~>3.0"
|
20
21
|
|
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: ..
|
9
9
|
specs:
|
10
|
-
vanity (2.0.0.
|
10
|
+
vanity (2.0.0.beta9)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -69,6 +69,7 @@ GEM
|
|
69
69
|
daemon_controller (1.0.0)
|
70
70
|
erubis (2.7.0)
|
71
71
|
execjs (2.5.2)
|
72
|
+
fakefs (0.6.7)
|
72
73
|
fast-stemmer (1.0.2)
|
73
74
|
ffi (1.9.8)
|
74
75
|
garb (0.9.1)
|
@@ -132,7 +133,6 @@ GEM
|
|
132
133
|
rake (>= 0.8.1)
|
133
134
|
polyglot (0.3.5)
|
134
135
|
posix-spawn (0.3.11)
|
135
|
-
power_assert (0.2.2)
|
136
136
|
pygments.rb (0.6.3)
|
137
137
|
posix-spawn (~> 0.3.6)
|
138
138
|
yajl-ruby (~> 1.2.0)
|
@@ -177,8 +177,6 @@ GEM
|
|
177
177
|
rack (~> 1.0)
|
178
178
|
tilt (~> 1.1, != 1.3.0)
|
179
179
|
sqlite3 (1.3.10)
|
180
|
-
test-unit (3.0.9)
|
181
|
-
power_assert
|
182
180
|
thor (0.19.1)
|
183
181
|
tilt (1.4.1)
|
184
182
|
timecop (0.3.5)
|
@@ -206,12 +204,14 @@ DEPENDENCIES
|
|
206
204
|
appraisal (~> 1.0.2)
|
207
205
|
bson_ext
|
208
206
|
bundler (>= 1.0.0)
|
207
|
+
fakefs
|
209
208
|
fastthread!
|
210
209
|
garb (< 0.9.2)
|
211
210
|
integration (<= 0.1.0)
|
212
211
|
jdbc-sqlite3
|
213
212
|
jekyll
|
214
213
|
minitest (~> 4.2.0)
|
214
|
+
minitest_tu_shim (~> 1.3.3)
|
215
215
|
mocha (~> 1.0)
|
216
216
|
mongo
|
217
217
|
passenger (~> 3.0)
|
@@ -222,7 +222,6 @@ DEPENDENCIES
|
|
222
222
|
redis-namespace (>= 1.1.0)
|
223
223
|
rubystats
|
224
224
|
sqlite3 (~> 1.3.10)
|
225
|
-
test-unit (~> 3.0)
|
226
225
|
timecop
|
227
226
|
vanity!
|
228
227
|
webmock
|
data/gemfiles/rails4.gemfile
CHANGED
@@ -8,10 +8,11 @@ gem "redis-namespace", ">= 1.1.0"
|
|
8
8
|
gem "mongo"
|
9
9
|
gem "integration", "<= 0.1.0"
|
10
10
|
gem "rubystats"
|
11
|
-
gem "garb", "< 0.9.2"
|
11
|
+
gem "garb", "< 0.9.2", :require=>false
|
12
12
|
gem "timecop", :require => false
|
13
13
|
gem "webmock", :require => false
|
14
14
|
gem "mocha", "~> 1.0", :require => false
|
15
|
+
gem "fakefs", :require=>"fakefs/safe"
|
15
16
|
gem "rails", "4.0.13"
|
16
17
|
gem "fastthread", :git => "git://github.com/zoltankiss/fastthread.git", :platforms => :mri_20
|
17
18
|
gem "passenger", "~>3.0"
|
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: ..
|
9
9
|
specs:
|
10
|
-
vanity (2.0.0.
|
10
|
+
vanity (2.0.0.beta9)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -62,6 +62,7 @@ GEM
|
|
62
62
|
directory_watcher (1.4.1)
|
63
63
|
erubis (2.7.0)
|
64
64
|
fast-stemmer (1.0.2)
|
65
|
+
fakefs (0.6.7)
|
65
66
|
garb (0.9.1)
|
66
67
|
activesupport (>= 2.2.0)
|
67
68
|
crack (>= 0.1.6)
|
@@ -151,6 +152,7 @@ DEPENDENCIES
|
|
151
152
|
appraisal (~> 1.0.2)
|
152
153
|
bson_ext
|
153
154
|
bundler (>= 1.0.0)
|
155
|
+
fakefs
|
154
156
|
fastthread!
|
155
157
|
garb (< 0.9.2)
|
156
158
|
integration (<= 0.1.0)
|
data/gemfiles/rails41.gemfile
CHANGED
@@ -8,10 +8,11 @@ gem "redis-namespace", ">= 1.1.0"
|
|
8
8
|
gem "mongo"
|
9
9
|
gem "integration", "<= 0.1.0"
|
10
10
|
gem "rubystats"
|
11
|
-
gem "garb", "< 0.9.2"
|
11
|
+
gem "garb", "< 0.9.2", :require=>false
|
12
12
|
gem "timecop", :require => false
|
13
13
|
gem "webmock", :require => false
|
14
14
|
gem "mocha", "~> 1.0", :require => false
|
15
|
+
gem "fakefs", :require=>"fakefs/safe"
|
15
16
|
gem "rails", "4.1.9"
|
16
17
|
gem "fastthread", :git => "git://github.com/zoltankiss/fastthread.git", :platforms => :mri_20
|
17
18
|
gem "passenger", "~>3.0"
|
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: .././
|
9
9
|
specs:
|
10
|
-
vanity (2.0.0.
|
10
|
+
vanity (2.0.0.beta9)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -69,6 +69,7 @@ GEM
|
|
69
69
|
daemon_controller (1.2.0)
|
70
70
|
erubis (2.7.0)
|
71
71
|
execjs (2.5.2)
|
72
|
+
fakefs (0.6.7)
|
72
73
|
fast-stemmer (1.0.2)
|
73
74
|
ffi (1.9.8)
|
74
75
|
garb (0.9.1)
|
@@ -200,6 +201,7 @@ DEPENDENCIES
|
|
200
201
|
appraisal (~> 1.0.2)
|
201
202
|
bson_ext
|
202
203
|
bundler (>= 1.0.0)
|
204
|
+
fakefs
|
203
205
|
fastthread!
|
204
206
|
garb (< 0.9.2)
|
205
207
|
integration (<= 0.1.0)
|
data/gemfiles/rails42.gemfile
CHANGED
@@ -8,10 +8,11 @@ gem "redis-namespace", ">= 1.1.0"
|
|
8
8
|
gem "mongo"
|
9
9
|
gem "integration", "<= 0.1.0"
|
10
10
|
gem "rubystats"
|
11
|
-
gem "garb", "< 0.9.2"
|
11
|
+
gem "garb", "< 0.9.2", :require=>false
|
12
12
|
gem "timecop", :require => false
|
13
13
|
gem "webmock", :require => false
|
14
14
|
gem "mocha", "~> 1.0", :require => false
|
15
|
+
gem "fakefs", :require=>"fakefs/safe"
|
15
16
|
gem "rails", "4.2.0"
|
16
17
|
gem "fastthread", :git => "git://github.com/zoltankiss/fastthread.git", :platforms => :mri_20
|
17
18
|
gem "passenger", "~>3.0"
|
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: ..
|
9
9
|
specs:
|
10
|
-
vanity (2.0.0.
|
10
|
+
vanity (2.0.0.beta9)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -78,6 +78,7 @@ GEM
|
|
78
78
|
daemon_controller (1.2.0)
|
79
79
|
erubis (2.7.0)
|
80
80
|
execjs (2.5.2)
|
81
|
+
fakefs (0.6.7)
|
81
82
|
fast-stemmer (1.0.2)
|
82
83
|
ffi (1.9.8)
|
83
84
|
garb (0.9.1)
|
@@ -226,6 +227,7 @@ DEPENDENCIES
|
|
226
227
|
appraisal (~> 1.0.2)
|
227
228
|
bson_ext
|
228
229
|
bundler (>= 1.0.0)
|
230
|
+
fakefs
|
229
231
|
fastthread!
|
230
232
|
garb (< 0.9.2)
|
231
233
|
integration (<= 0.1.0)
|
data/lib/vanity.rb
CHANGED
@@ -11,25 +11,31 @@ require "yaml"
|
|
11
11
|
# @see Vanity::Playground
|
12
12
|
# @see Vanity::Metric
|
13
13
|
# @see Vanity::Experiment
|
14
|
+
# @see Vanity::Configuration
|
15
|
+
# @see Vanity::Connection
|
14
16
|
module Vanity
|
15
17
|
end
|
16
18
|
|
17
19
|
require "vanity/version"
|
18
|
-
# Metrics
|
20
|
+
# Metrics
|
19
21
|
require "vanity/metric/base"
|
20
22
|
require "vanity/metric/active_record"
|
21
23
|
require "vanity/metric/google_analytics"
|
22
24
|
require "vanity/metric/remote"
|
23
|
-
# Experiments
|
25
|
+
# Experiments
|
24
26
|
require "vanity/experiment/base"
|
25
27
|
require "vanity/experiment/ab_test"
|
26
28
|
# Database adapters
|
29
|
+
require "vanity/adapters"
|
27
30
|
require "vanity/adapters/abstract_adapter"
|
28
31
|
require "vanity/adapters/mock_adapter"
|
29
|
-
# Playground
|
32
|
+
# Playground
|
30
33
|
require "vanity/playground"
|
31
|
-
require "vanity/
|
34
|
+
require "vanity/configuration"
|
35
|
+
require "vanity/connection"
|
32
36
|
require "vanity/autoconnect"
|
37
|
+
require "vanity/templates"
|
33
38
|
require "vanity/helpers"
|
34
|
-
|
39
|
+
require "vanity/vanity"
|
40
|
+
# Integration with various frameworks
|
35
41
|
require "vanity/frameworks"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Vanity
|
2
|
+
module Adapters
|
3
|
+
class << self
|
4
|
+
# Creates new connection to underlying datastore and returns suitable
|
5
|
+
# adapter (adapter object extends AbstractAdapter and wraps the
|
6
|
+
# connection). Vanity.playground.establish_connection uses this.
|
7
|
+
#
|
8
|
+
# @since 1.4.0
|
9
|
+
def establish_connection(spec)
|
10
|
+
begin
|
11
|
+
require "vanity/adapters/#{spec[:adapter]}_adapter"
|
12
|
+
rescue LoadError
|
13
|
+
raise "Could not find #{spec[:adapter]} in your load path"
|
14
|
+
end
|
15
|
+
adapter_method = "#{spec[:adapter]}_connection"
|
16
|
+
send adapter_method, spec
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,23 +1,5 @@
|
|
1
1
|
module Vanity
|
2
2
|
module Adapters
|
3
|
-
|
4
|
-
class << self
|
5
|
-
# Creates new connection to underlying datastore and returns suitable
|
6
|
-
# adapter (adapter object extends AbstractAdapter and wraps the
|
7
|
-
# connection). Vanity.playground.establish_connection uses this.
|
8
|
-
#
|
9
|
-
# @since 1.4.0
|
10
|
-
def establish_connection(spec)
|
11
|
-
begin
|
12
|
-
require "vanity/adapters/#{spec[:adapter]}_adapter"
|
13
|
-
rescue LoadError
|
14
|
-
raise "Could not find #{spec[:adapter]} in your load path"
|
15
|
-
end
|
16
|
-
adapter_method = "#{spec[:adapter]}_connection"
|
17
|
-
send adapter_method, spec
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
3
|
# Base class for all adapters. Adapters wrap underlying connection to a
|
22
4
|
# datastore and implement an API that Vanity can use to store/access
|
23
5
|
# metrics, experiments, etc.
|
data/lib/vanity/autoconnect.rb
CHANGED
@@ -0,0 +1,211 @@
|
|
1
|
+
module Vanity
|
2
|
+
# This class holds the "how" Vanity operates. For the "what", please see
|
3
|
+
# Vanity::Playground.
|
4
|
+
class Configuration
|
5
|
+
class MissingEnvironment < StandardError; end
|
6
|
+
|
7
|
+
LEGACY_REDIS_CONFIG_FILE = "redis.yml"
|
8
|
+
|
9
|
+
class<<self
|
10
|
+
private
|
11
|
+
|
12
|
+
def default_logger # :nodoc:
|
13
|
+
logger = Logger.new(STDOUT)
|
14
|
+
logger.level = Logger::WARN
|
15
|
+
logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_on_datastore_error(error, klass, method, arguments) # :nodoc:
|
19
|
+
log = "[#{Time.now.iso8601}]"
|
20
|
+
log << " [vanity #{klass} #{method}]"
|
21
|
+
log << " [#{error.message}]"
|
22
|
+
log << " [#{arguments.join(' ')}]"
|
23
|
+
Vanity.logger.error(log)
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def default_request_filter(request) # :nodoc:
|
28
|
+
request &&
|
29
|
+
request.env &&
|
30
|
+
request.env["HTTP_USER_AGENT"] &&
|
31
|
+
request.env["HTTP_USER_AGENT"].match(/\(.*https?:\/\/.*\)/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
DEFAULTS = {
|
36
|
+
collecting: true,
|
37
|
+
experiments_path: File.join(Pathname.new("."), "experiments"),
|
38
|
+
add_participant_route: "/vanity/add_participant",
|
39
|
+
logger: default_logger,
|
40
|
+
failover_on_datastore_error: false,
|
41
|
+
on_datastore_error: ->(error, klass, method, arguments) {
|
42
|
+
default_on_datastore_error(error, klass, method, arguments)
|
43
|
+
},
|
44
|
+
request_filter: ->(request) { default_request_filter(request) },
|
45
|
+
templates_path: File.expand_path(File.join(File.dirname(__FILE__), 'templates')),
|
46
|
+
locales_path: File.expand_path(File.join(File.dirname(__FILE__), 'locales')),
|
47
|
+
use_js: false,
|
48
|
+
config_path: File.join(Pathname.new("."), "config"),
|
49
|
+
config_file: "vanity.yml",
|
50
|
+
environment: ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
|
51
|
+
}.freeze
|
52
|
+
|
53
|
+
# True if saving results to the datastore (participants and conversions).
|
54
|
+
attr_writer :collecting
|
55
|
+
|
56
|
+
# Path to load experiment files from.
|
57
|
+
attr_writer :experiments_path
|
58
|
+
|
59
|
+
# URL to the add_participant action.
|
60
|
+
attr_writer :add_participant_route
|
61
|
+
|
62
|
+
# Logger. The default logs to STDOUT.
|
63
|
+
attr_writer :logger
|
64
|
+
|
65
|
+
# -- Datastore graceful failover --
|
66
|
+
|
67
|
+
# Turns on passing of errors to the Proc returned by #on_datastore_error.
|
68
|
+
# Set `config.failover_on_datastore_error` to `true` to turn this on.
|
69
|
+
#
|
70
|
+
# @since 2.0.0
|
71
|
+
attr_writer :failover_on_datastore_error
|
72
|
+
|
73
|
+
# Must return a Proc that accepts as parameters: the thrown error, the
|
74
|
+
# calling Class, the calling method, and an array of arguments passed to
|
75
|
+
# the calling method. The return value is ignored.
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
# Proc.new do |error, klass, method, arguments|
|
79
|
+
# ...
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# The default implementation logs this information to Playground#logger.
|
83
|
+
#
|
84
|
+
# Set a custom action by calling config.on_datastore_error =
|
85
|
+
# Proc.new { ... }.
|
86
|
+
#
|
87
|
+
# @since 2.0.0
|
88
|
+
attr_writer :on_datastore_error
|
89
|
+
|
90
|
+
# -- Blocking or ignoring visitors --
|
91
|
+
|
92
|
+
# Must return a Proc that accepts as a parameter the request object, if
|
93
|
+
# made available by the implement framework. The return value should be a
|
94
|
+
# boolean whether to ignore the request. This is called only for the JS
|
95
|
+
# callback action.
|
96
|
+
#
|
97
|
+
# @example
|
98
|
+
# Proc.new do |request|
|
99
|
+
# ...
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# The default implementation does a simple test of whether the request's
|
103
|
+
# HTTP_USER_AGENT header contains a URI, since well behaved bots typically
|
104
|
+
# include a reference URI in their user agent strings. (Original idea:
|
105
|
+
# http://stackoverflow.com/a/9285889.)
|
106
|
+
#
|
107
|
+
# Alternatively, one could filter an explicit list of IPs, add additional
|
108
|
+
# user agent strings to filter, or any custom test. Set a custom filter
|
109
|
+
# by calling config.request_filter = Proc.new { ... }.
|
110
|
+
#
|
111
|
+
# @since 2.0.0
|
112
|
+
attr_writer :request_filter
|
113
|
+
|
114
|
+
# Path to Vanity templates. Set this to override those in the gem.
|
115
|
+
attr_writer :templates_path
|
116
|
+
|
117
|
+
# Path to Vanity locales. Set this to override those in the gem.
|
118
|
+
attr_writer :locales_path
|
119
|
+
|
120
|
+
# -- Robot Detection --
|
121
|
+
|
122
|
+
# Call to indicate that participants should be added via js. This helps
|
123
|
+
# keep robots from participating in the A/B test and skewing results.
|
124
|
+
#
|
125
|
+
# If you want to use this:
|
126
|
+
# - Add <%= vanity_js %> to any page that needs uses an ab_test. vanity_js
|
127
|
+
# needs to be included after your call to ab_test so that it knows which
|
128
|
+
# version of the experiment the participant is a member of. The helper
|
129
|
+
# will render nothing if the there are no ab_tests running on the current
|
130
|
+
# page, so adding vanity_js to the bottom of your layouts is a good
|
131
|
+
# option. Keep in mind that if you set config.use_js = true and don't include
|
132
|
+
# vanity_js in your view no participants will be recorded.
|
133
|
+
#
|
134
|
+
# Note that a custom JS callback path can be set using:
|
135
|
+
# - Set config.add_participant_route = '/path/to/vanity/action',
|
136
|
+
# this should point to the add_participant path that is added with
|
137
|
+
# Vanity::Rails::Dashboard, make sure that this action is available
|
138
|
+
# to all users.
|
139
|
+
attr_writer :use_js
|
140
|
+
# Uses ./config by default.
|
141
|
+
attr_writer :config_path
|
142
|
+
# By default the vanity.yml file in the config_path variable. Variables
|
143
|
+
# scoped under the key for the current environment are extracted for the
|
144
|
+
# connection parameters. If there is no config/vanity.yml file, tries the
|
145
|
+
# configuration from config/redis.yml.
|
146
|
+
attr_writer :config_file
|
147
|
+
# In order of precedence, RACK_ENV, RAILS_ENV or `development`.
|
148
|
+
attr_writer :environment
|
149
|
+
|
150
|
+
|
151
|
+
# We independently list each attr_accessor to includes docs, otherwise
|
152
|
+
# something like DEFAULTS.each { |key, value| attr_accessor key } would be
|
153
|
+
# shorter.
|
154
|
+
DEFAULTS.each do |default, value|
|
155
|
+
define_method default do
|
156
|
+
self[default]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def [](arg)
|
161
|
+
if instance_variable_defined?("@#{arg}")
|
162
|
+
instance_variable_get("@#{arg}")
|
163
|
+
else
|
164
|
+
DEFAULTS[arg]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def setup_locales
|
169
|
+
locales = Dir[File.join(locales_path, '*.{rb,yml}')]
|
170
|
+
I18n.load_path += locales
|
171
|
+
end
|
172
|
+
|
173
|
+
# @return nil or a hash of symbolized keys for connection settings
|
174
|
+
def connection_params(file_name=nil)
|
175
|
+
file_name ||= config_file
|
176
|
+
file_path = File.join(config_path, file_name)
|
177
|
+
|
178
|
+
if File.exists?(file_path)
|
179
|
+
config = YAML.load(ERB.new(File.read(file_path)).result)
|
180
|
+
config ||= {}
|
181
|
+
params_for_environment = config[environment.to_s]
|
182
|
+
|
183
|
+
unless params_for_environment
|
184
|
+
raise MissingEnvironment.new("No configuration for #{environment}")
|
185
|
+
end
|
186
|
+
|
187
|
+
# Symbolize keys if it's a hash.
|
188
|
+
if params_for_environment.respond_to?(:inject)
|
189
|
+
params_for_environment.inject({}) { |h,kv| h[kv.first.to_sym] = kv.last ; h }
|
190
|
+
else
|
191
|
+
params_for_environment
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# @deprecated
|
197
|
+
def redis_url_from_file
|
198
|
+
connection_url = connection_params(LEGACY_REDIS_CONFIG_FILE)
|
199
|
+
|
200
|
+
if connection_url
|
201
|
+
logger.warn(%q{Deprecated: Please specify the vanity config file, the default fallback to "config/redis.yml" may be removed in a future version.})
|
202
|
+
|
203
|
+
if connection_url =~ /^\w+:/
|
204
|
+
connection_url
|
205
|
+
else
|
206
|
+
"redis://" + connection_url
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|