vanity 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +41 -0
- data/Rakefile +1 -1
- data/doc/_layouts/page.html +1 -0
- data/doc/adapters.textile +64 -0
- data/gemfiles/rails32.gemfile +1 -1
- data/gemfiles/rails32.gemfile.lock +2 -2
- data/gemfiles/rails41.gemfile +1 -1
- data/gemfiles/rails41.gemfile.lock +2 -2
- data/gemfiles/rails42.gemfile +1 -1
- data/gemfiles/rails42.gemfile.lock +2 -2
- data/gemfiles/rails42_protected_attributes.gemfile +1 -1
- data/gemfiles/rails42_protected_attributes.gemfile.lock +35 -7
- data/lib/generators/templates/vanity_migration.rb +65 -47
- data/lib/vanity/adapters.rb +5 -2
- data/lib/vanity/autoconnect.rb +20 -13
- data/lib/vanity/connection.rb +1 -3
- data/lib/vanity/version.rb +1 -1
- data/test/autoconnect_test.rb +11 -5
- data/test/connection_test.rb +0 -6
- data/test/test_helper.rb +10 -2
- metadata +4 -4
- data/.autotest +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b02356f60ed8be58e0e5daff561be8a9d67abf80
|
4
|
+
data.tar.gz: 67f7b8f914b146f60d9258be4644de3ba3f5b750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27da9c6c6f8e869394a40ae9c43a0cce464a9b2abf471b9d8afbfcac2a751c192496857e5950c255787e699bb4c58e0cd1969d3594a8522bd5c0f95a7dd72047
|
7
|
+
data.tar.gz: ca525881cd422ceed0b3b0417840e71bfbc7bc492449be71f54debc58437980936f297267c1c7967405c8794c27877e99c0f219c52024fe4155250c49612c53b
|
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vanity (2.2.
|
4
|
+
vanity (2.2.1)
|
5
5
|
i18n
|
6
6
|
|
7
7
|
GEM
|
@@ -120,7 +120,7 @@ DEPENDENCIES
|
|
120
120
|
garb (< 0.9.2)
|
121
121
|
integration (<= 0.1.0)
|
122
122
|
jdbc-sqlite3
|
123
|
-
jekyll
|
123
|
+
jekyll (~> 2.5.3)
|
124
124
|
minitest (>= 4.2)
|
125
125
|
mongo (~> 2.1)
|
126
126
|
rack
|
data/README.md
CHANGED
@@ -60,6 +60,15 @@ test:
|
|
60
60
|
collecting: false
|
61
61
|
```
|
62
62
|
|
63
|
+
To re-use an existing redis connection, you can call `Vanity.connect!` explicitly, for example:
|
64
|
+
|
65
|
+
```
|
66
|
+
Vanity.connect!(
|
67
|
+
adapter: :redis,
|
68
|
+
redis: $redis
|
69
|
+
)
|
70
|
+
```
|
71
|
+
|
63
72
|
##### MongoDB Setup
|
64
73
|
|
65
74
|
Add to your Gemfile:
|
@@ -120,6 +129,38 @@ $ rails generate vanity
|
|
120
129
|
$ rake db:migrate
|
121
130
|
```
|
122
131
|
|
132
|
+
##### Forking servers and reconnecting
|
133
|
+
|
134
|
+
If you're using a forking server (like Passenger or Unicorn), you should
|
135
|
+
reconnect after a new worker is created:
|
136
|
+
|
137
|
+
```
|
138
|
+
# unicorn.rb
|
139
|
+
after_fork do |server, worker|
|
140
|
+
defined?(Vanity) && Vanity.reconnect!
|
141
|
+
end
|
142
|
+
|
143
|
+
# an initializer
|
144
|
+
if defined?(PhusionPassenger)
|
145
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
146
|
+
# We're in smart spawning mode.
|
147
|
+
if forked
|
148
|
+
defined?(Vanity) && Vanity.reconnect!
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
If you're using explicit options with `Vanity.connect!`, you should call `disconnect!` first, for example:
|
155
|
+
|
156
|
+
```
|
157
|
+
Vanity.disconnect!
|
158
|
+
Vanity.connect!(
|
159
|
+
adapter: 'redis',
|
160
|
+
redis: $redis
|
161
|
+
)
|
162
|
+
```
|
163
|
+
|
123
164
|
#### Step 1.3
|
124
165
|
|
125
166
|
Turn Vanity on, and pass a reference to a method that identifies a user. For
|
data/Rakefile
CHANGED
@@ -80,7 +80,7 @@ task(:clobber) { rm_rf "tmp" }
|
|
80
80
|
# -- Documenting stuff -- #TODO make sure works under 1.9/2.0
|
81
81
|
|
82
82
|
desc "Jekyll generates the main documentation (sans API)"
|
83
|
-
task(:jekyll) { sh "jekyll
|
83
|
+
task(:jekyll) { sh "jekyll build -s doc -d html" }
|
84
84
|
|
85
85
|
desc "Create documentation in docs directory"
|
86
86
|
task :docs=>[:jekyll]
|
data/doc/_layouts/page.html
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
<li><a href="email.html">Testing emails</a></li>
|
28
28
|
<li><a href="identity.html">Managing Identity</a></li>
|
29
29
|
<li><a href="configuring.html">Configuring</a></li>
|
30
|
+
<li><a href="adapters.html">Adapters</a></li>
|
30
31
|
<li><a href="contributing.html">Contributing</a></li>
|
31
32
|
<li><a href="experimental.html">Experimental</a></li>
|
32
33
|
</ul>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
---
|
2
|
+
layout: page
|
3
|
+
title: Adapters
|
4
|
+
---
|
5
|
+
|
6
|
+
Adapters let Vanity
|
7
|
+
|
8
|
+
h3(#officially-supported). Officially Supported
|
9
|
+
|
10
|
+
* "Redis adapter":https://github.com/assaf/vanity/blob/master/lib/vanity/adapters/redis_adapter.rb
|
11
|
+
* "Activerecord adapter":https://github.com/assaf/vanity/blob/master/lib/vanity/adapters/active_record_adapter.rb
|
12
|
+
* "Mongo adapter":https://github.com/assaf/vanity/blob/master/lib/vanity/adapters/mongodb_adapter.rb
|
13
|
+
* "Mock adapter":https://github.com/assaf/vanity/blob/master/lib/vanity/adapters/mock_adapter.rb (an in-memory store good for testing)
|
14
|
+
|
15
|
+
h3(#community-supported). Community Supported
|
16
|
+
|
17
|
+
Have one out there? "Open a PR to update these docs!":contributing.html
|
18
|
+
|
19
|
+
h3(#building-an-adapter). Building an Adapter
|
20
|
+
|
21
|
+
An adapter "should inherit from AbstractAdapter":https://github.com/assaf/vanity/blob/master/lib/vanity/adapters/abstract_adapter.rb . It should wrap an underlying connection to a datastore and implement an API that Vanity can use to store/access metrics and experiments.
|
22
|
+
|
23
|
+
A good place to start when creating your own adapter is to copy one of the adapters mentioned above and replace the client specific code with whatever client you are attempting to adapt.
|
24
|
+
|
25
|
+
The API for an adapter is divided into four categories: connections, metrics methods, experiment configuration methods and experiment data methods.
|
26
|
+
|
27
|
+
h4. Connection methods
|
28
|
+
|
29
|
+
* active?
|
30
|
+
* disconnect!
|
31
|
+
* reconnect!
|
32
|
+
* flushdb
|
33
|
+
|
34
|
+
h4. Metric methods
|
35
|
+
|
36
|
+
* get_metric_last_update_at(metric)
|
37
|
+
* metric_track(metric, timestamp, identity, values)
|
38
|
+
* metric_values(metric, from, to)
|
39
|
+
* destroy_metric(metric)
|
40
|
+
|
41
|
+
h4. Experiment configuration methods
|
42
|
+
|
43
|
+
* experiment_persisted?(experiment)
|
44
|
+
* set_experiment_created_at(experiment, time)
|
45
|
+
* get_experiment_created_at(experiment)
|
46
|
+
* is_experiment_completed?(experiment)
|
47
|
+
* set_experiment_enabled(experiment, enabled)
|
48
|
+
* is_experiment_enabled?(experiment)
|
49
|
+
* destroy_experiment(experiment)
|
50
|
+
|
51
|
+
h4. Experiment data methods
|
52
|
+
|
53
|
+
These ab_* methods interact with the underlying data of an experiment.
|
54
|
+
|
55
|
+
* ab_counts(experiment, alternative)
|
56
|
+
* ab_show(experiment, identity, alternative)
|
57
|
+
* ab_showing(experiment, identity)
|
58
|
+
* ab_not_showing(experiment, identity)
|
59
|
+
* ab_add_participant(experiment, alternative, identity)
|
60
|
+
* ab_seen(experiment, identity, assignment)
|
61
|
+
* ab_assigned(experiment, identity)
|
62
|
+
* ab_add_conversion(experiment, alternative, identity, count, implicit)
|
63
|
+
* ab_get_outcome(experiment)
|
64
|
+
* ab_set_outcome(experiment, alternative)
|
data/gemfiles/rails32.gemfile
CHANGED
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: ..
|
9
9
|
specs:
|
10
|
-
vanity (2.2.
|
10
|
+
vanity (2.2.1)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -208,7 +208,7 @@ DEPENDENCIES
|
|
208
208
|
garb (< 0.9.2)
|
209
209
|
integration (<= 0.1.0)
|
210
210
|
jdbc-sqlite3
|
211
|
-
jekyll
|
211
|
+
jekyll (~> 2.5.3)
|
212
212
|
minitest (~> 4.2.0)
|
213
213
|
minitest_tu_shim (~> 1.3.3)
|
214
214
|
mocha (~> 1.0)
|
data/gemfiles/rails41.gemfile
CHANGED
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: .././
|
9
9
|
specs:
|
10
|
-
vanity (2.2.
|
10
|
+
vanity (2.2.1)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -200,7 +200,7 @@ DEPENDENCIES
|
|
200
200
|
garb (< 0.9.2)
|
201
201
|
integration (<= 0.1.0)
|
202
202
|
jdbc-sqlite3
|
203
|
-
jekyll
|
203
|
+
jekyll (~> 2.5.3)
|
204
204
|
minitest (>= 4.2)
|
205
205
|
mocha (~> 1.0)
|
206
206
|
mongo (~> 2.1)
|
data/gemfiles/rails42.gemfile
CHANGED
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: ..
|
9
9
|
specs:
|
10
|
-
vanity (2.2.
|
10
|
+
vanity (2.2.1)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -226,7 +226,7 @@ DEPENDENCIES
|
|
226
226
|
garb (< 0.9.2)
|
227
227
|
integration (<= 0.1.0)
|
228
228
|
jdbc-sqlite3
|
229
|
-
jekyll
|
229
|
+
jekyll (~> 2.5.3)
|
230
230
|
minitest (>= 4.2)
|
231
231
|
mocha (~> 1.0)
|
232
232
|
mongo (~> 2.1)
|
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: ../
|
9
9
|
specs:
|
10
|
-
vanity (2.2.
|
10
|
+
vanity (2.2.1)
|
11
11
|
i18n
|
12
12
|
|
13
13
|
GEM
|
@@ -55,15 +55,24 @@ GEM
|
|
55
55
|
rake
|
56
56
|
thor (>= 0.14.0)
|
57
57
|
arel (6.0.3)
|
58
|
+
blankslate (2.1.2.4)
|
58
59
|
bson (4.0.2)
|
59
60
|
builder (3.2.2)
|
61
|
+
classifier-reborn (2.0.3)
|
62
|
+
fast-stemmer (~> 1.0)
|
63
|
+
coffee-script (2.4.1)
|
64
|
+
coffee-script-source
|
65
|
+
execjs
|
66
|
+
coffee-script-source (1.9.1)
|
60
67
|
colorator (0.1)
|
61
68
|
concurrent-ruby (1.0.0)
|
62
69
|
crack (0.4.3)
|
63
70
|
safe_yaml (~> 1.0.0)
|
64
71
|
daemon_controller (1.2.0)
|
65
72
|
erubis (2.7.0)
|
73
|
+
execjs (2.5.2)
|
66
74
|
fakefs (0.6.7)
|
75
|
+
fast-stemmer (1.0.2)
|
67
76
|
ffi (1.9.10)
|
68
77
|
garb (0.9.1)
|
69
78
|
activesupport (>= 2.2.0)
|
@@ -73,22 +82,32 @@ GEM
|
|
73
82
|
hashdiff (0.2.3)
|
74
83
|
i18n (0.7.0)
|
75
84
|
integration (0.1.0)
|
76
|
-
jekyll (
|
85
|
+
jekyll (2.5.3)
|
86
|
+
classifier-reborn (~> 2.0)
|
77
87
|
colorator (~> 0.1)
|
88
|
+
jekyll-coffeescript (~> 1.0)
|
89
|
+
jekyll-gist (~> 1.0)
|
90
|
+
jekyll-paginate (~> 1.0)
|
78
91
|
jekyll-sass-converter (~> 1.0)
|
79
92
|
jekyll-watch (~> 1.1)
|
80
93
|
kramdown (~> 1.3)
|
81
|
-
liquid (~>
|
94
|
+
liquid (~> 2.6.1)
|
82
95
|
mercenary (~> 0.3.3)
|
83
|
-
|
96
|
+
pygments.rb (~> 0.6.0)
|
97
|
+
redcarpet (~> 3.1)
|
84
98
|
safe_yaml (~> 1.0)
|
99
|
+
toml (~> 0.1.0)
|
100
|
+
jekyll-coffeescript (1.0.1)
|
101
|
+
coffee-script (~> 2.2)
|
102
|
+
jekyll-gist (1.2.1)
|
103
|
+
jekyll-paginate (1.1.0)
|
85
104
|
jekyll-sass-converter (1.4.0)
|
86
105
|
sass (~> 3.4)
|
87
106
|
jekyll-watch (1.3.0)
|
88
107
|
listen (~> 3.0)
|
89
108
|
json (1.8.3)
|
90
109
|
kramdown (1.9.0)
|
91
|
-
liquid (
|
110
|
+
liquid (2.6.2)
|
92
111
|
listen (3.0.5)
|
93
112
|
rb-fsevent (>= 0.9.3)
|
94
113
|
rb-inotify (>= 0.9)
|
@@ -107,13 +126,19 @@ GEM
|
|
107
126
|
bson (~> 4.0)
|
108
127
|
nokogiri (1.6.7.1)
|
109
128
|
mini_portile2 (~> 2.0.0.rc2)
|
129
|
+
parslet (1.5.0)
|
130
|
+
blankslate (~> 2.0)
|
110
131
|
passenger (3.0.21)
|
111
132
|
daemon_controller (>= 1.0.0)
|
112
133
|
fastthread (>= 1.0.1)
|
113
134
|
rack
|
114
135
|
rake (>= 0.8.1)
|
136
|
+
posix-spawn (0.3.11)
|
115
137
|
protected_attributes (1.1.0)
|
116
138
|
activemodel (>= 4.0.1, < 5.0)
|
139
|
+
pygments.rb (0.6.3)
|
140
|
+
posix-spawn (~> 0.3.6)
|
141
|
+
yajl-ruby (~> 1.2.0)
|
117
142
|
rack (1.6.4)
|
118
143
|
rack-test (0.6.3)
|
119
144
|
rack (>= 1.0)
|
@@ -145,10 +170,10 @@ GEM
|
|
145
170
|
rb-fsevent (0.9.7)
|
146
171
|
rb-inotify (0.9.5)
|
147
172
|
ffi (>= 0.5.0)
|
173
|
+
redcarpet (3.2.3)
|
148
174
|
redis (3.2.2)
|
149
175
|
redis-namespace (1.5.2)
|
150
176
|
redis (~> 3.0, >= 3.0.4)
|
151
|
-
rouge (1.10.1)
|
152
177
|
rubystats (0.2.4)
|
153
178
|
safe_yaml (1.0.4)
|
154
179
|
sass (3.4.20)
|
@@ -163,12 +188,15 @@ GEM
|
|
163
188
|
thor (0.19.1)
|
164
189
|
thread_safe (0.3.5)
|
165
190
|
timecop (0.8.0)
|
191
|
+
toml (0.1.2)
|
192
|
+
parslet (~> 1.5.0)
|
166
193
|
tzinfo (1.2.2)
|
167
194
|
thread_safe (~> 0.1)
|
168
195
|
webmock (1.22.5)
|
169
196
|
addressable (< 2.4.0)
|
170
197
|
crack (>= 0.3.2)
|
171
198
|
hashdiff
|
199
|
+
yajl-ruby (1.2.1)
|
172
200
|
yard (0.8.7.6)
|
173
201
|
|
174
202
|
PLATFORMS
|
@@ -184,7 +212,7 @@ DEPENDENCIES
|
|
184
212
|
garb (< 0.9.2)
|
185
213
|
integration (<= 0.1.0)
|
186
214
|
jdbc-sqlite3
|
187
|
-
jekyll
|
215
|
+
jekyll (~> 2.5.3)
|
188
216
|
minitest (>= 4.2)
|
189
217
|
mocha (~> 1.0)
|
190
218
|
mongo (~> 2.1)
|
@@ -1,55 +1,73 @@
|
|
1
1
|
class VanityMigration < ActiveRecord::Migration
|
2
|
-
|
3
|
-
|
4
|
-
t.string :metric_id
|
5
|
-
t.datetime :updated_at
|
6
|
-
end
|
7
|
-
add_index :vanity_metrics, [:metric_id]
|
2
|
+
# Helper methods to ensure we're connecting to the right database, see
|
3
|
+
# https://github.com/assaf/vanity/issues/295.
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
t.string :date
|
14
|
-
end
|
15
|
-
add_index :vanity_metric_values, [:vanity_metric_id, :date]
|
16
|
-
|
17
|
-
create_table :vanity_experiments do |t|
|
18
|
-
t.string :experiment_id
|
19
|
-
t.integer :outcome
|
20
|
-
t.boolean :enabled
|
21
|
-
t.datetime :created_at
|
22
|
-
t.datetime :completed_at
|
23
|
-
end
|
24
|
-
add_index :vanity_experiments, [:experiment_id]
|
5
|
+
def connection
|
6
|
+
@connection ||= ActiveRecord::Base.connection
|
7
|
+
end
|
8
|
+
alias_method :default_connection, :connection
|
25
9
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
10
|
+
def with_vanity_connection
|
11
|
+
@connection = Vanity::Adapters::ActiveRecordAdapter::VanityRecord.connection
|
12
|
+
yield
|
13
|
+
@connection = default_connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def up
|
17
|
+
with_vanity_connection do
|
18
|
+
create_table :vanity_metrics do |t|
|
19
|
+
t.string :metric_id
|
20
|
+
t.datetime :updated_at
|
21
|
+
end
|
22
|
+
add_index :vanity_metrics, [:metric_id]
|
23
|
+
|
24
|
+
create_table :vanity_metric_values do |t|
|
25
|
+
t.integer :vanity_metric_id
|
26
|
+
t.integer :index
|
27
|
+
t.integer :value
|
28
|
+
t.string :date
|
29
|
+
end
|
30
|
+
add_index :vanity_metric_values, [:vanity_metric_id, :date]
|
31
|
+
|
32
|
+
create_table :vanity_experiments do |t|
|
33
|
+
t.string :experiment_id
|
34
|
+
t.integer :outcome
|
35
|
+
t.boolean :enabled
|
36
|
+
t.datetime :created_at
|
37
|
+
t.datetime :completed_at
|
38
|
+
end
|
39
|
+
add_index :vanity_experiments, [:experiment_id]
|
40
|
+
|
41
|
+
create_table :vanity_conversions do |t|
|
42
|
+
t.integer :vanity_experiment_id
|
43
|
+
t.integer :alternative
|
44
|
+
t.integer :conversions
|
45
|
+
end
|
46
|
+
add_index :vanity_conversions, [:vanity_experiment_id, :alternative], :name => "by_experiment_id_and_alternative"
|
47
|
+
|
48
|
+
create_table :vanity_participants do |t|
|
49
|
+
t.string :experiment_id
|
50
|
+
t.string :identity
|
51
|
+
t.integer :shown
|
52
|
+
t.integer :seen
|
53
|
+
t.integer :converted
|
54
|
+
t.timestamps
|
55
|
+
end
|
56
|
+
add_index :vanity_participants, [:experiment_id]
|
57
|
+
add_index :vanity_participants, [:experiment_id, :identity], :name => "by_experiment_id_and_identity"
|
58
|
+
add_index :vanity_participants, [:experiment_id, :shown], :name => "by_experiment_id_and_shown"
|
59
|
+
add_index :vanity_participants, [:experiment_id, :seen], :name => "by_experiment_id_and_seen"
|
60
|
+
add_index :vanity_participants, [:experiment_id, :converted], :name => "by_experiment_id_and_converted"
|
40
61
|
end
|
41
|
-
add_index :vanity_participants, [:experiment_id]
|
42
|
-
add_index :vanity_participants, [:experiment_id, :identity], :name => "by_experiment_id_and_identity"
|
43
|
-
add_index :vanity_participants, [:experiment_id, :shown], :name => "by_experiment_id_and_shown"
|
44
|
-
add_index :vanity_participants, [:experiment_id, :seen], :name => "by_experiment_id_and_seen"
|
45
|
-
add_index :vanity_participants, [:experiment_id, :converted], :name => "by_experiment_id_and_converted"
|
46
62
|
end
|
47
63
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
64
|
+
def down
|
65
|
+
with_vanity_connection do
|
66
|
+
drop_table :vanity_metrics
|
67
|
+
drop_table :vanity_metric_values
|
68
|
+
drop_table :vanity_experiments
|
69
|
+
drop_table :vanity_conversions
|
70
|
+
drop_table :vanity_participants
|
71
|
+
end
|
54
72
|
end
|
55
73
|
end
|
data/lib/vanity/adapters.rb
CHANGED
@@ -3,17 +3,20 @@ module Vanity
|
|
3
3
|
class << self
|
4
4
|
# Creates new connection to underlying datastore and returns suitable
|
5
5
|
# adapter (adapter object extends AbstractAdapter and wraps the
|
6
|
-
# connection).
|
6
|
+
# connection).
|
7
7
|
#
|
8
8
|
# @since 1.4.0
|
9
9
|
def establish_connection(spec)
|
10
|
+
return unless Autoconnect.should_connect? ||
|
11
|
+
(Autoconnect.schema_relevant? && spec[:adapter].to_s == 'active_record')
|
12
|
+
|
10
13
|
begin
|
11
14
|
require "vanity/adapters/#{spec[:adapter]}_adapter"
|
12
15
|
rescue LoadError
|
13
16
|
raise "Could not find #{spec[:adapter]} in your load path"
|
14
17
|
end
|
15
18
|
adapter_method = "#{spec[:adapter]}_connection"
|
16
|
-
send
|
19
|
+
send(adapter_method, spec)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
data/lib/vanity/autoconnect.rb
CHANGED
@@ -42,22 +42,29 @@ module Vanity
|
|
42
42
|
]
|
43
43
|
ENVIRONMENT_VANITY_DISABLED_FLAG = "VANITY_DISABLED"
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
class << self
|
46
|
+
def should_connect?
|
47
|
+
!environment_disabled? && !in_blacklisted_rake_task?
|
48
|
+
end
|
49
|
+
alias_method :playground_should_autoconnect?, :should_connect?
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
def schema_relevant?
|
52
|
+
current_rake_tasks.any? { |task| task =~ /\Adb:/ }
|
53
|
+
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
def environment_disabled?
|
56
|
+
!!ENV[ENVIRONMENT_VANITY_DISABLED_FLAG]
|
57
|
+
end
|
58
|
+
|
59
|
+
def in_blacklisted_rake_task?
|
60
|
+
!(current_rake_tasks & BLACKLISTED_RAILS_RAKE_TASKS).empty?
|
61
|
+
end
|
56
62
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
def current_rake_tasks
|
64
|
+
::Rake.application.top_level_tasks
|
65
|
+
rescue => e
|
66
|
+
[]
|
67
|
+
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
end
|
data/lib/vanity/connection.rb
CHANGED
@@ -33,9 +33,7 @@ module Vanity
|
|
33
33
|
def initialize(specification=nil)
|
34
34
|
@specification = specification || DEFAULT_SPECIFICATION
|
35
35
|
|
36
|
-
|
37
|
-
@adapter = setup_connection(@specification)
|
38
|
-
end
|
36
|
+
@adapter = setup_connection(@specification)
|
39
37
|
end
|
40
38
|
|
41
39
|
# Closes the current connection.
|
data/lib/vanity/version.rb
CHANGED
data/test/autoconnect_test.rb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
describe Vanity::Autoconnect do
|
4
|
-
describe ".
|
5
|
-
|
4
|
+
describe ".should_connect?" do
|
6
5
|
it "returns true by default" do
|
7
|
-
autoconnect = Vanity::Autoconnect.
|
6
|
+
autoconnect = Vanity::Autoconnect.should_connect?
|
8
7
|
assert autoconnect == true
|
9
8
|
end
|
10
9
|
|
11
10
|
it "returns false if environment flag is set" do
|
12
11
|
ENV['VANITY_DISABLED'] = '1'
|
13
|
-
autoconnect = Vanity::Autoconnect.
|
12
|
+
autoconnect = Vanity::Autoconnect.should_connect?
|
14
13
|
assert autoconnect == false
|
15
14
|
ENV['VANITY_DISABLED'] = nil
|
16
15
|
end
|
17
16
|
|
18
17
|
it "returns false if in assets:precompile rake task" do
|
19
18
|
Rake.expects(:application).returns(stub(:top_level_tasks => ['assets:precompile']))
|
20
|
-
autoconnect = Vanity::Autoconnect.
|
19
|
+
autoconnect = Vanity::Autoconnect.should_connect?
|
21
20
|
assert autoconnect == false
|
22
21
|
end
|
23
22
|
end
|
23
|
+
|
24
|
+
describe ".schema_relevant?" do
|
25
|
+
it "returns true for database tasks" do
|
26
|
+
Rake.expects(:application).returns(stub(:top_level_tasks => ['db:migrate']))
|
27
|
+
assert_equal true, Vanity::Autoconnect.schema_relevant?
|
28
|
+
end
|
29
|
+
end
|
24
30
|
end
|
data/test/connection_test.rb
CHANGED
@@ -12,12 +12,6 @@ describe Vanity::Connection do
|
|
12
12
|
Vanity::Connection.new(adapter: "mock")
|
13
13
|
end
|
14
14
|
|
15
|
-
it "can skip connection" do
|
16
|
-
Vanity::Autoconnect.stubs(:playground_should_autoconnect?).returns(false)
|
17
|
-
connection = Vanity::Connection.new(adapter: "mock")
|
18
|
-
assert !connection.connected?
|
19
|
-
end
|
20
|
-
|
21
15
|
it "parses from a string" do
|
22
16
|
Vanity::Adapters.expects(:establish_connection).with(
|
23
17
|
adapter: 'redis',
|
data/test/test_helper.rb
CHANGED
@@ -198,7 +198,15 @@ if ENV["DB"] == "active_record"
|
|
198
198
|
ActiveRecord::Base.establish_connection
|
199
199
|
ActiveRecord::Base.logger = $logger
|
200
200
|
|
201
|
+
Vanity.connect!(VanityTestHelpers::DATABASE)
|
201
202
|
require "generators/templates/vanity_migration"
|
202
|
-
|
203
|
-
|
203
|
+
if defined?(ActiveRecord::Tasks)
|
204
|
+
config = Vanity::Adapters::ActiveRecordAdapter::VanityRecord.connection_config
|
205
|
+
ActiveRecord::Tasks::DatabaseTasks.drop(config.with_indifferent_access)
|
206
|
+
else # Rails 3.2 fallback
|
207
|
+
klasses = Vanity::Adapters::ActiveRecordAdapter::VanityRecord.descendants
|
208
|
+
klasses.each { |k| k.connection.drop_table(k.table_name) if k.connection.table_exists?(k.table_name) }
|
209
|
+
end
|
210
|
+
|
211
|
+
VanityMigration.new.migrate(:up)
|
204
212
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Assaf Arkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -61,7 +61,6 @@ extra_rdoc_files:
|
|
61
61
|
- README.md
|
62
62
|
- CHANGELOG
|
63
63
|
files:
|
64
|
-
- .autotest
|
65
64
|
- .gitignore
|
66
65
|
- .travis.yml
|
67
66
|
- Appraisals
|
@@ -77,6 +76,7 @@ files:
|
|
77
76
|
- doc/_layouts/page.html
|
78
77
|
- doc/_metrics.textile
|
79
78
|
- doc/ab_testing.textile
|
79
|
+
- doc/adapters.textile
|
80
80
|
- doc/configuring.textile
|
81
81
|
- doc/contributing.textile
|
82
82
|
- doc/credits.textile
|
@@ -213,7 +213,7 @@ metadata: {}
|
|
213
213
|
post_install_message: To get started run vanity --help
|
214
214
|
rdoc_options:
|
215
215
|
- --title
|
216
|
-
- Vanity 2.2.
|
216
|
+
- Vanity 2.2.1
|
217
217
|
- --main
|
218
218
|
- README.md
|
219
219
|
- --webcvs
|
data/.autotest
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
Autotest.add_hook :initialize do |autotest|
|
3
|
-
%w{.git .DS_Store Gemfile bin doc html}.each do |exception|
|
4
|
-
autotest.add_exception(exception)
|
5
|
-
end
|
6
|
-
autotest.clear_mappings
|
7
|
-
autotest.add_mapping(/^test.*\/.*_test\.rb$/) { |filename, _| filename }
|
8
|
-
autotest.add_mapping(/test_helper.rb/) { |f, _| autotest.files_matching(/test\/.*_test\.rb$/) }
|
9
|
-
autotest.add_mapping(/^lib\/vanity\/(.*)\.rb/) do |filename, _|
|
10
|
-
file = File.basename(filename, '.rb')
|
11
|
-
dir = File.split(File.dirname(filename)).last
|
12
|
-
autotest.files_matching %r%^test/(#{file}|#{dir})_test.rb$%
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
# Don't run entire test suite when going from red to green
|
18
|
-
class Autotest
|
19
|
-
def tainted
|
20
|
-
false
|
21
|
-
end
|
22
|
-
end
|