ar-multidb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -1,15 +1,19 @@
1
1
  module Multidb
2
2
 
3
3
  class Candidate
4
- def initialize(config)
5
- adapter = config[:adapter]
6
- begin
7
- require "active_record/connection_adapters/#{adapter}_adapter"
8
- rescue LoadError
9
- raise "Please install the #{adapter} adapter: `gem install activerecord-#{adapter}-adapter` (#{$!})"
4
+ def initialize(target)
5
+ if target.is_a?(Hash)
6
+ adapter = target[:adapter]
7
+ begin
8
+ require "active_record/connection_adapters/#{adapter}_adapter"
9
+ rescue LoadError
10
+ raise "Please install the #{adapter} adapter: `gem install activerecord-#{adapter}-adapter` (#{$!})"
11
+ end
12
+ @connection_pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(
13
+ ActiveRecord::Base::ConnectionSpecification.new(target, "#{adapter}_connection"))
14
+ else
15
+ @connection_pool = target
10
16
  end
11
- @connection_pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(
12
- ActiveRecord::Base::ConnectionSpecification.new(config, "#{adapter}_connection"))
13
17
  end
14
18
 
15
19
  def connection
@@ -30,7 +34,7 @@ module Multidb
30
34
  @candidates[name].push(candidate)
31
35
  end
32
36
  end
33
- @default_candidate = Candidate.new(@configuration.default_adapter)
37
+ @default_candidate = Candidate.new(@configuration.default_pool)
34
38
  unless @candidates.include?(:default)
35
39
  @candidates[:default] = [@default_candidate]
36
40
  end
@@ -15,10 +15,12 @@ module Multidb
15
15
 
16
16
  class Configuration
17
17
  def initialize(default_adapter, configuration_hash)
18
+ @default_pool = ActiveRecord::Base.connection_pool
18
19
  @default_adapter = default_adapter
19
20
  @raw_configuration = configuration_hash
20
21
  end
21
22
 
23
+ attr_reader :default_pool
22
24
  attr_reader :default_adapter
23
25
  attr_reader :raw_configuration
24
26
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-multidb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Staubo