active_record_host_pool 2.0.0.pre.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4c99be0433d92bea15d4c49896f356536455e944e7b11e2ae7f7ea53b3e7d1a
4
- data.tar.gz: 96a0b0d168ea82987e4e128263351c23dd80c390abed82d187e73393f0003b80
3
+ metadata.gz: 0ba0aa0ff3c0b19e4895118e76f84cc57f46481baa482c59925946ecd56765bb
4
+ data.tar.gz: e276dbda95168a03b511a5d7da14f94411ca7b8bc910ea2684631f25c9a22cf1
5
5
  SHA512:
6
- metadata.gz: 2fadaf3620e2adad2931483ad3d6f1d379e3ab252872245c7cf1e3fe3133bfc2dda16ecb8f83632d4898fd850621d064393a84078edc0e2c62338cb67aecd080
7
- data.tar.gz: b28ac1e4864dc7c0d9ed8924132af7394b9144ec5a77a55e1d99ce2a3863209f8cb1967732dc628675bbc580ef252189c49891f473fd56ccbff00aca42464c50
6
+ metadata.gz: 5b455f5fd116f96035fa816b39e0baf7f698d885decece79fd213c690c07db6b2f54e2328d4fa8dab68c536e86b58a9261b3c1a4c8aa45ccf35c1cb7b237168e
7
+ data.tar.gz: aa7295a9be8e2892ff34452de014ea7627255d58e6eccd6a0d4a18d3b03152adb18fb2e453df017a058eeaf26bf8d4a768db3e436cef7da498f69e03d5f50917
data/Changelog.md CHANGED
@@ -6,7 +6,15 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [2.0.0.pre.2]
9
+ ## [2.1.0]
10
+
11
+ ### Changed
12
+ - ActiveRecordHostPool now uses prepend to patch `#execute`, `#raw_execute`, `#drop_database`, `#create_database`, and `#disconnect!`. Prepending is incompatible when also using `alias` or `alias_method` to patch those methods; avoid aliasing them to prevent an infinite loop.
13
+
14
+ ### Removed
15
+ - Dropped support for Ruby 2.7.x.
16
+
17
+ ## [2.0.0]
10
18
 
11
19
  ### Added
12
20
  - Add support for Rails 7.1.
@@ -16,6 +24,9 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
16
24
  - Remove `mysql2` as a direct dependency, test Rails 7.0 with `mysql2` and `activerecord-trilogy-adapter`.
17
25
  - Remove support for Rails 5.1, 5.2, and 6.0.
18
26
 
27
+ ### Fixed
28
+ - Implement equality for connection proxies to consider database; allows fixture loading for different databases
29
+
19
30
  ## [1.2.5] - 2023-07-14
20
31
  ### Added
21
32
  - Start testing with Ruby 3.2.
@@ -18,32 +18,7 @@ end
18
18
 
19
19
  module ActiveRecordHostPool
20
20
  module DatabaseSwitch
21
- def self.included(base)
22
- base.class_eval do
23
- attr_reader(:_host_pool_current_database)
24
-
25
- # Patch `raw_execute` instead of `execute` since this commit:
26
- # https://github.com/rails/rails/commit/f69bbcbc0752ca5d5af327d55922614a26f5c7e9
27
- case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
28
- when "7.1"
29
- alias_method :raw_execute_without_switching, :raw_execute
30
- alias_method :raw_execute, :raw_execute_with_switching
31
- else
32
- alias_method :execute_without_switching, :execute
33
- alias_method :execute, :execute_with_switching
34
- end
35
-
36
- alias_method :drop_database_without_no_switching, :drop_database
37
- alias_method :drop_database, :drop_database_with_no_switching
38
-
39
- alias_method :create_database_without_no_switching, :create_database
40
- alias_method :create_database, :create_database_with_no_switching
41
-
42
- alias_method :disconnect_without_host_pooling!, :disconnect!
43
- alias_method :disconnect!, :disconnect_with_host_pooling!
44
- end
45
- end
46
-
21
+ attr_reader :_host_pool_current_database
47
22
  def initialize(*)
48
23
  @_cached_current_database = nil
49
24
  super
@@ -54,44 +29,42 @@ module ActiveRecordHostPool
54
29
  @config[:database] = _host_pool_current_database
55
30
  end
56
31
 
57
- def self.ruby2_keywords(*); end unless respond_to?(:ruby2_keywords, true)
58
- # This one really does need ruby2_keywords; in Rails 6.0 the method does not take
59
- # any keyword arguments, but in Rails 7.0+ it does. So, we don't know whether or not
60
- # what we're delegating to takes kwargs, so ruby2_keywords is needed.
61
32
  if ActiveRecord.version >= Gem::Version.new("7.1")
62
- ruby2_keywords def raw_execute_with_switching(*args)
33
+ # Patch `raw_execute` instead of `execute` since this commit:
34
+ # https://github.com/rails/rails/commit/f69bbcbc0752ca5d5af327d55922614a26f5c7e9
35
+ def raw_execute(...)
63
36
  if _host_pool_current_database && !_no_switch
64
37
  _switch_connection
65
38
  end
66
- raw_execute_without_switching(*args)
39
+ super
67
40
  end
68
41
  else
69
- ruby2_keywords def execute_with_switching(*args)
42
+ def execute(...)
70
43
  if _host_pool_current_database && !_no_switch
71
44
  _switch_connection
72
45
  end
73
- execute_without_switching(*args)
46
+ super
74
47
  end
75
48
  end
76
49
 
77
- def drop_database_with_no_switching(*args)
50
+ def drop_database(...)
78
51
  self._no_switch = true
79
- drop_database_without_no_switching(*args)
52
+ super
80
53
  ensure
81
54
  self._no_switch = false
82
55
  end
83
56
 
84
- def create_database_with_no_switching(*args)
57
+ def create_database(...)
85
58
  self._no_switch = true
86
- create_database_without_no_switching(*args)
59
+ super
87
60
  ensure
88
61
  self._no_switch = false
89
62
  end
90
63
 
91
- def disconnect_with_host_pooling!
64
+ def disconnect!
92
65
  @_cached_current_database = nil
93
66
  @_cached_connection_object_id = nil
94
- disconnect_without_host_pooling!
67
+ super
95
68
  end
96
69
 
97
70
  private
@@ -130,9 +103,9 @@ end
130
103
 
131
104
  case ActiveRecordHostPool.loaded_db_adapter
132
105
  when :mysql2
133
- ActiveRecord::ConnectionAdapters::Mysql2Adapter.include(ActiveRecordHostPool::DatabaseSwitch)
106
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
134
107
  when :trilogy
135
- ActiveRecord::ConnectionAdapters::TrilogyAdapter.include(ActiveRecordHostPool::DatabaseSwitch)
108
+ ActiveRecord::ConnectionAdapters::TrilogyAdapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
136
109
  end
137
110
 
138
111
  ActiveRecord::ConnectionAdapters::PoolConfig.prepend(ActiveRecordHostPool::PoolConfigPatch)
@@ -6,6 +6,7 @@ require "delegate"
6
6
  # for each call to the connection. upon executing a statement, the connection will switch to that database.
7
7
  module ActiveRecordHostPool
8
8
  class ConnectionProxy < Delegator
9
+ attr_reader :database
9
10
  def initialize(cx, database)
10
11
  super(cx)
11
12
  @cx = cx
@@ -43,20 +44,30 @@ module ActiveRecordHostPool
43
44
  __getobj__.private_methods(all) | super
44
45
  end
45
46
 
46
- def send(symbol, *args, &blk)
47
+ def send(symbol, ...)
47
48
  if respond_to?(symbol, true) && !__getobj__.respond_to?(symbol, true)
48
49
  super
49
50
  else
50
- __getobj__.send(symbol, *args, &blk)
51
+ __getobj__.send(symbol, ...)
51
52
  end
52
53
  end
53
- ruby2_keywords :send if respond_to?(:ruby2_keywords, true)
54
+
55
+ def ==(other)
56
+ self.class == other.class &&
57
+ other.respond_to?(:unproxied) && @cx == other.unproxied &&
58
+ other.respond_to?(:database) && @database == other.database
59
+ end
60
+
61
+ alias_method :eql?, :==
62
+
63
+ def hash
64
+ [self.class, @cx, @database].hash
65
+ end
54
66
 
55
67
  private
56
68
 
57
- def select(*args)
58
- @cx.__send__(:select, *args)
69
+ def select(...)
70
+ @cx.__send__(:select, ...)
59
71
  end
60
- ruby2_keywords :select if respond_to?(:ruby2_keywords, true)
61
72
  end
62
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordHostPool
4
- VERSION = "2.0.0.pre.2"
4
+ VERSION = "2.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_host_pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Quorning
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-11-21 00:00:00.000000000 Z
14
+ date: 2024-04-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -65,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 2.7.0
68
+ version: 3.0.0
69
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ">"
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 1.3.1
73
+ version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.0.3.1
75
+ rubygems_version: 3.5.3
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Allow ActiveRecord to share a connection to multiple databases on the same