active_record_shards 2.6.7 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -167,10 +167,19 @@ module ActiveRecordShards
167
167
  # in 3.2 rails is asking for a connection pool in a map of these ConnectionSpecifications. If we want to re-use connections,
168
168
  # we need to re-use specs.
169
169
 
170
- specification_cache[name] ||= ActiveRecord::Base::ConnectionSpecification.new(spec, "#{spec['adapter']}_connection")
171
- cx_spec = specification_cache[name]
170
+ # note that since we're subverting the standard establish_connection path, we have to handle the funky autoloading of the
171
+ # connection adapter ourselves.
172
+ specification_cache[name] ||= begin
173
+ if ActiveRecord::VERSION::STRING >= "3.2.0"
174
+ resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new spec, configurations
175
+ resolver.spec
176
+ else
177
+ autoload_adapter(spec['adapter'])
178
+ ActiveRecord::Base::ConnectionSpecification.new(spec, "#{spec['adapter']}_connection")
179
+ end
180
+ end
172
181
 
173
- connection_handler.establish_connection(connection_pool_name, cx_spec)
182
+ connection_handler.establish_connection(connection_pool_name, specification_cache[name])
174
183
  end
175
184
 
176
185
  def specification_cache
@@ -207,6 +216,25 @@ module ActiveRecordShards
207
216
  result
208
217
  end
209
218
 
219
+ def autoload_adapter(adapter_name)
220
+ begin
221
+ require 'rubygems'
222
+ gem "activerecord-#{adapter_name}-adapter"
223
+ require "active_record/connection_adapters/#{adapter_name}_adapter"
224
+ rescue LoadError
225
+ begin
226
+ require "active_record/connection_adapters/#{adapter_name}_adapter"
227
+ rescue LoadError
228
+ raise "Please install the #{adapter_name} adapter: `gem install activerecord-#{adapter_name}-adapter` (#{$!})"
229
+ end
230
+ end
231
+
232
+ adapter_method = "#{adapter_name}_connection"
233
+ if !ActiveRecord::Base.respond_to?(adapter_name + "_connection")
234
+ raise AdapterNotFound, "database configuration specifies nonexistent #{adapter_name} adapter"
235
+ end
236
+ end
237
+
210
238
  class MasterSlaveProxy
211
239
  def initialize(target, which)
212
240
  @target = target
data/test/helper.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+
3
4
  Bundler.setup
4
5
  Bundler.require(:default, :development)
5
6
 
7
+ require 'mocha'
8
+
6
9
  if defined?(Debugger)
7
10
  ::Debugger.start
8
11
  ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.7
4
+ version: 2.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-01-16 00:00:00.000000000 Z
14
+ date: 2013-02-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -120,17 +120,17 @@ dependencies:
120
120
  requirement: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ! '>='
123
+ - - '='
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 0.12.0
126
126
  type: :development
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
131
- - - ! '>='
131
+ - - '='
132
132
  - !ruby/object:Gem::Version
133
- version: '0'
133
+ version: 0.12.0
134
134
  - !ruby/object:Gem::Dependency
135
135
  name: appraisal
136
136
  requirement: !ruby/object:Gem::Requirement
@@ -147,22 +147,6 @@ dependencies:
147
147
  - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
- - !ruby/object:Gem::Dependency
151
- name: yaggy
152
- requirement: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- type: :development
159
- prerelease: false
160
- version_requirements: !ruby/object:Gem::Requirement
161
- none: false
162
- requirements:
163
- - - ! '>='
164
- - !ruby/object:Gem::Version
165
- version: '0'
166
150
  - !ruby/object:Gem::Dependency
167
151
  name: test-unit
168
152
  requirement: !ruby/object:Gem::Requirement
@@ -240,18 +224,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
224
  - - ! '>='
241
225
  - !ruby/object:Gem::Version
242
226
  version: '0'
243
- segments:
244
- - 0
245
- hash: -349916606155063800
246
227
  required_rubygems_version: !ruby/object:Gem::Requirement
247
228
  none: false
248
229
  requirements:
249
230
  - - ! '>='
250
231
  - !ruby/object:Gem::Version
251
232
  version: '0'
252
- segments:
253
- - 0
254
- hash: -349916606155063800
255
233
  requirements: []
256
234
  rubyforge_project:
257
235
  rubygems_version: 1.8.24