rails_multisite 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails_multisite might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a68463a7504b939ebae5583bd1a83cc54fa88c6a
4
- data.tar.gz: d4770c86628b9a0a22294121322089c14cfffb79
3
+ metadata.gz: 46f1af53002fa575bb2ef12f53aedb834bd146f7
4
+ data.tar.gz: 16a65e7ea6a754641070e3867388082f447e0c82
5
5
  SHA512:
6
- metadata.gz: c245a17c26cc9125df4a7726437ab07b5803a2b2b4b36192522c10e43b8ef014ef197a233641e802c6ee5bf6c65502ab85cf6915a69e213d61330dc91f778e06
7
- data.tar.gz: 4202d63fd048a87b2d7645734022a68df77ea4aa4587c7ad46d50a59b647095e156df62738c15aba2aa12a6f811971d05cd1fecfa332f811ea6025604ede3c00
6
+ metadata.gz: 583ec55ba16263a8c9e442cb405bd3f74cbb4825e556a9df0307c38a0f331a601702e22b3d647e343d2bd856c8b94f76a4d223b3b87b21cd9eb3d58f0b2b0e1f
7
+ data.tar.gz: 19ec7b4f342e3b940be2ee5951cc038dcca679c01628de691a460d9d168f2cd07cee8a79113fd1499c5820de213558d958c73c9e217c2388ff0a02a55d42291d
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record'
2
4
  require 'rails'
3
- require "rails_multisite/version"
4
- require "rails_multisite/railtie"
5
- require "rails_multisite/formatter"
6
- require "rails_multisite/connection_management"
5
+ require 'rails_multisite/version'
6
+ require 'rails_multisite/railtie'
7
+ require 'rails_multisite/formatter'
8
+ require 'rails_multisite/connection_management'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  module RailsMultisite
2
4
  class ConnectionManagement
3
5
  CONFIG_FILE = 'config/multisite.yml'
4
- DEFAULT = 'default'.freeze
6
+ DEFAULT = 'default'
5
7
 
6
8
  def self.has_db?(db)
7
9
  return true if db == DEFAULT
@@ -50,13 +52,13 @@ module RailsMultisite
50
52
  old = current_hostname
51
53
  connected = ActiveRecord::Base.connection_pool.connected?
52
54
 
53
- establish_connection(:host => hostname) unless connected && hostname == old
55
+ establish_connection(host: hostname) unless connected && hostname == old
54
56
  rval = yield hostname
55
57
 
56
58
  unless connected && hostname == old
57
59
  ActiveRecord::Base.connection_handler.clear_active_connections!
58
60
 
59
- establish_connection(:host => old)
61
+ establish_connection(host: old)
60
62
  ActiveRecord::Base.connection_handler.clear_active_connections! unless connected
61
63
  end
62
64
 
@@ -67,20 +69,20 @@ module RailsMultisite
67
69
  old = current_db
68
70
  connected = ActiveRecord::Base.connection_pool.connected?
69
71
 
70
- establish_connection(:db => db) unless connected && db == old
72
+ establish_connection(db: db) unless connected && db == old
71
73
  rval = yield db
72
74
 
73
75
  unless connected && db == old
74
76
  ActiveRecord::Base.connection_handler.clear_active_connections!
75
77
 
76
- establish_connection(:db => old)
78
+ establish_connection(db: old)
77
79
  ActiveRecord::Base.connection_handler.clear_active_connections! unless connected
78
80
  end
79
81
 
80
82
  rval
81
83
  end
82
84
 
83
- def self.each_connection(opts=nil, &blk)
85
+ def self.each_connection(opts = nil, &blk)
84
86
 
85
87
  old = current_db
86
88
  connected = ActiveRecord::Base.connection_pool.connected?
@@ -90,7 +92,7 @@ module RailsMultisite
90
92
 
91
93
  if (opts && (threads = opts[:threads]))
92
94
  queue = Queue.new
93
- all_dbs.each{|db| queue << db}
95
+ all_dbs.each { |db| queue << db }
94
96
  end
95
97
 
96
98
  errors = nil
@@ -108,7 +110,7 @@ module RailsMultisite
108
110
 
109
111
  break unless db
110
112
 
111
- establish_connection(:db => db)
113
+ establish_connection(db: db)
112
114
  # no choice but to rescue, should probably log
113
115
 
114
116
  begin
@@ -122,7 +124,7 @@ module RailsMultisite
122
124
  end.map(&:join)
123
125
  else
124
126
  all_dbs.each do |db|
125
- establish_connection(:db => db)
127
+ establish_connection(db: db)
126
128
  blk.call(db)
127
129
  ActiveRecord::Base.connection_handler.clear_active_connections!
128
130
  end
@@ -132,9 +134,8 @@ module RailsMultisite
132
134
  raise StandardError, "Failed to run queries #{errors.inspect}"
133
135
  end
134
136
 
135
-
136
137
  ensure
137
- establish_connection(:db => old)
138
+ establish_connection(db: old)
138
139
  ActiveRecord::Base.connection_handler.clear_active_connections! unless connected
139
140
  end
140
141
 
@@ -181,7 +182,7 @@ module RailsMultisite
181
182
 
182
183
  no_prepared_statements = ActiveRecord::Base.configurations[Rails.env]["prepared_statements"] == false
183
184
 
184
- configs.each do |k,v|
185
+ configs.each do |k, v|
185
186
  raise ArgumentError.new("Please do not name any db default!") if k == DEFAULT
186
187
  v[:db_key] = k
187
188
  v[:prepared_statements] = false if no_prepared_statements
@@ -191,7 +192,7 @@ module RailsMultisite
191
192
  @@db_spec_cache = Hash[*configs.map { |k, _| [k, resolver.spec(k.to_sym)] }.flatten]
192
193
 
193
194
  @@host_spec_cache = {}
194
- configs.each do |k,v|
195
+ configs.each do |k, v|
195
196
  next unless v["host_names"]
196
197
  v["host_names"].each do |host|
197
198
  @@host_spec_cache[host] = @@db_spec_cache[k]
@@ -209,9 +210,9 @@ module RailsMultisite
209
210
  @@established_default = false
210
211
  end
211
212
 
212
-
213
213
  def initialize(app, config = nil)
214
214
  @app = app
215
+ @db_lookup = config && config[:db_lookup]
215
216
  end
216
217
 
217
218
  def self.host(env)
@@ -221,13 +222,20 @@ module RailsMultisite
221
222
 
222
223
  def call(env)
223
224
  host = self.class.host(env)
225
+ db = nil
224
226
  begin
225
227
 
226
- #TODO: add a callback so users can simply go to a domain to register it, or something
227
- return [404, {}, ["not found"]] unless @@host_spec_cache[host]
228
+ unless @@host_spec_cache[host]
229
+ db = @db_lookup && @db_lookup.call(env)
230
+ if db
231
+ host = nil
232
+ else
233
+ return [404, {}, ["not found"]]
234
+ end
235
+ end
228
236
 
229
237
  ActiveRecord::Base.connection_handler.clear_active_connections!
230
- self.class.establish_connection(:host => host)
238
+ self.class.establish_connection(host: host, db: db)
231
239
  @app.call(env)
232
240
  ensure
233
241
  ActiveRecord::Base.connection_handler.clear_active_connections!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  module RailsMultisite
2
4
  class Formatter < ::ActiveSupport::Logger::SimpleFormatter
3
5
  include ::ActiveSupport::TaggedLogging::Formatter
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsMultisite
2
4
  class Railtie < Rails::Railtie
3
5
  rake_tasks do
4
- Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
6
+ Dir[File.join(File.dirname(__FILE__), '../tasks/*.rake')].each { |f| load f }
5
7
  end
6
8
 
7
9
  initializer "RailsMultisite.init" do |app|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  module RailsMultisite
2
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
3
5
  end
@@ -1,6 +1,6 @@
1
1
  desc "generate multisite config file (if missing)"
2
2
  task "multisite:generate:config" => :environment do
3
- filename = RailsMultisite::ConnectionManagement.config_filename
3
+ filename = RailsMultisite::ConnectionManagement.config_filename
4
4
 
5
5
  if File.exists?(filename)
6
6
  puts "Config is already generated at #{RailsMultisite::ConnectionManagement::CONFIG_FILE}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_multisite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: '0'
80
+ version: 2.2.0
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="