rails_multisite 8.0.0 → 9.0.0
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.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 42d7959bbb9536ba5902f2532aa20c14db3365de98bf8b6b20c0612c12be583e
|
|
4
|
+
data.tar.gz: bc05e6e85d428d3b4785b58e3468d884df30224a47f63f032620e66d854abb57
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3fc63f60cd559f3ed57895a30620b0cc7b2a0de8a19124a40f8e79f04985805eac39d95edb0873c907ca4488badc2985ddade7b07851d5205226a5cb61621ef
|
|
7
|
+
data.tar.gz: 960da8f7bbe5534911f6269ff493250e6520b927d238299ad17efcdc5f0b357b02cd11267433fb618e4d3853a0ab159b4ab3c9f0fcd0680783928549239343c8
|
|
@@ -14,7 +14,10 @@ module RailsMultisite
|
|
|
14
14
|
def default_connection_handler=(_connection_handler)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def establish_connection(
|
|
17
|
+
def establish_connection(db: nil, host: nil, raise_on_missing: true)
|
|
18
|
+
if !host && !has_db?(db.to_s) && raise_on_missing
|
|
19
|
+
raise UnknownSiteError.new(db)
|
|
20
|
+
end
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
def reload
|
|
@@ -44,16 +47,18 @@ module RailsMultisite
|
|
|
44
47
|
env["HTTP_HOST"]
|
|
45
48
|
end
|
|
46
49
|
|
|
47
|
-
def with_connection(db = DEFAULT, &blk)
|
|
50
|
+
def with_connection(db = DEFAULT, raise_on_missing: true, &blk)
|
|
51
|
+
raise UnknownSiteError.new(db) if !has_db?(db.to_s) && raise_on_missing
|
|
52
|
+
|
|
48
53
|
connected = ActiveRecord::Base.connection_pool.connected?
|
|
49
54
|
result = blk.call(db)
|
|
50
|
-
|
|
55
|
+
if !connected
|
|
51
56
|
ActiveRecord::Base.connection_handler.clear_active_connections!
|
|
52
57
|
end
|
|
53
58
|
result
|
|
54
59
|
end
|
|
55
60
|
|
|
56
|
-
def with_hostname(hostname, &blk)
|
|
61
|
+
def with_hostname(hostname, raise_on_missing: true, &blk)
|
|
57
62
|
blk.call(hostname)
|
|
58
63
|
end
|
|
59
64
|
end
|
|
@@ -4,6 +4,12 @@ require "rails_multisite/connection_management/connection_specification"
|
|
|
4
4
|
require "rails_multisite/connection_management/null_instance"
|
|
5
5
|
|
|
6
6
|
module RailsMultisite
|
|
7
|
+
class UnknownSiteError < StandardError
|
|
8
|
+
def initialize(db)
|
|
9
|
+
super("ERROR: #{db} not found!")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
7
13
|
class ConnectionManagement
|
|
8
14
|
DEFAULT = "default"
|
|
9
15
|
|
|
@@ -149,18 +155,20 @@ module RailsMultisite
|
|
|
149
155
|
db == DEFAULT || !!db_spec_cache[db]
|
|
150
156
|
end
|
|
151
157
|
|
|
152
|
-
def establish_connection(
|
|
153
|
-
|
|
158
|
+
def establish_connection(db: nil, host: nil, raise_on_missing: true)
|
|
159
|
+
db = db.to_s
|
|
154
160
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
spec =
|
|
162
|
+
if db == DEFAULT
|
|
163
|
+
@default_spec
|
|
164
|
+
elsif (found = connection_spec(db: db, host: host))
|
|
165
|
+
found
|
|
166
|
+
elsif raise_on_missing
|
|
167
|
+
raise UnknownSiteError.new(host || db)
|
|
168
|
+
else
|
|
169
|
+
@default_spec
|
|
160
170
|
end
|
|
161
|
-
end
|
|
162
171
|
|
|
163
|
-
spec ||= @default_spec
|
|
164
172
|
handler = nil
|
|
165
173
|
if spec != @default_spec
|
|
166
174
|
handler = connection_handlers[handler_key(spec)]
|
|
@@ -176,18 +184,20 @@ module RailsMultisite
|
|
|
176
184
|
ActiveRecord::Base.connection_handler = handler
|
|
177
185
|
end
|
|
178
186
|
|
|
179
|
-
def with_hostname(hostname)
|
|
187
|
+
def with_hostname(hostname, raise_on_missing: true)
|
|
180
188
|
old = current_hostname
|
|
181
189
|
connected = ActiveRecord::Base.connection_pool.connected?
|
|
182
190
|
|
|
183
|
-
|
|
191
|
+
if !(connected && hostname == old)
|
|
192
|
+
establish_connection(host: hostname, raise_on_missing: raise_on_missing)
|
|
193
|
+
end
|
|
184
194
|
rval = yield hostname
|
|
185
195
|
|
|
186
|
-
|
|
196
|
+
if !(connected && hostname == old)
|
|
187
197
|
ActiveRecord::Base.connection_handler.clear_active_connections!
|
|
188
198
|
|
|
189
|
-
establish_connection(host: old)
|
|
190
|
-
|
|
199
|
+
establish_connection(host: old, raise_on_missing: false)
|
|
200
|
+
if !connected
|
|
191
201
|
ActiveRecord::Base.connection_handler.clear_active_connections!
|
|
192
202
|
end
|
|
193
203
|
end
|
|
@@ -195,17 +205,19 @@ module RailsMultisite
|
|
|
195
205
|
rval
|
|
196
206
|
end
|
|
197
207
|
|
|
198
|
-
def with_connection(db = DEFAULT)
|
|
208
|
+
def with_connection(db = DEFAULT, raise_on_missing: true)
|
|
199
209
|
old = current_db
|
|
200
210
|
connected = ActiveRecord::Base.connection_pool.connected?
|
|
201
211
|
|
|
202
|
-
|
|
212
|
+
if !(connected && db == old)
|
|
213
|
+
establish_connection(db: db, raise_on_missing: raise_on_missing)
|
|
214
|
+
end
|
|
203
215
|
rval = yield db
|
|
204
216
|
|
|
205
|
-
|
|
217
|
+
if !(connected && db == old)
|
|
206
218
|
ActiveRecord::Base.connection_handler.clear_active_connections!
|
|
207
219
|
|
|
208
|
-
establish_connection(db: old)
|
|
220
|
+
establish_connection(db: old, raise_on_missing: false)
|
|
209
221
|
unless connected
|
|
210
222
|
ActiveRecord::Base.connection_handler.clear_active_connections!
|
|
211
223
|
end
|