active_record_host_pool 2.0.0 → 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: d6c85e552706dd86fe493aadff36c1c3cc6d9115ab9ee7bbfd627b3d684a02bd
4
- data.tar.gz: 7effa38f67de9456d748027f27544bbc4f07afacba671c505dd8d23645648572
3
+ metadata.gz: 0ba0aa0ff3c0b19e4895118e76f84cc57f46481baa482c59925946ecd56765bb
4
+ data.tar.gz: e276dbda95168a03b511a5d7da14f94411ca7b8bc910ea2684631f25c9a22cf1
5
5
  SHA512:
6
- metadata.gz: 8119ce55b8f44d7e29f195228c7055c1fe3c771916fc3ff31cc51e2db3ed7064c14db2424b6fdebf0a0a086e894cfb33faa97d87f1a16d272bff54957d3e20b0
7
- data.tar.gz: 885cb1e3676d698f93394eb8686af27d5b2d2f2d194f3e533a3a20f3272678a08caf92d6819d08002c989f637430f8eb4d9fddd66d5bbbdccafbbd006da44c57
6
+ metadata.gz: 5b455f5fd116f96035fa816b39e0baf7f698d885decece79fd213c690c07db6b2f54e2328d4fa8dab68c536e86b58a9261b3c1a4c8aa45ccf35c1cb7b237168e
7
+ data.tar.gz: aa7295a9be8e2892ff34452de014ea7627255d58e6eccd6a0d4a18d3b03152adb18fb2e453df017a058eeaf26bf8d4a768db3e436cef7da498f69e03d5f50917
data/Changelog.md CHANGED
@@ -6,6 +6,14 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
6
6
 
7
7
  ## [Unreleased]
8
8
 
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
+
9
17
  ## [2.0.0]
10
18
 
11
19
  ### Added
@@ -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)
@@ -44,14 +44,13 @@ module ActiveRecordHostPool
44
44
  __getobj__.private_methods(all) | super
45
45
  end
46
46
 
47
- def send(symbol, *args, &blk)
47
+ def send(symbol, ...)
48
48
  if respond_to?(symbol, true) && !__getobj__.respond_to?(symbol, true)
49
49
  super
50
50
  else
51
- __getobj__.send(symbol, *args, &blk)
51
+ __getobj__.send(symbol, ...)
52
52
  end
53
53
  end
54
- ruby2_keywords :send if respond_to?(:ruby2_keywords, true)
55
54
 
56
55
  def ==(other)
57
56
  self.class == other.class &&
@@ -67,9 +66,8 @@ module ActiveRecordHostPool
67
66
 
68
67
  private
69
68
 
70
- def select(*args)
71
- @cx.__send__(:select, *args)
69
+ def select(...)
70
+ @cx.__send__(:select, ...)
72
71
  end
73
- ruby2_keywords :select if respond_to?(:ruby2_keywords, true)
74
72
  end
75
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordHostPool
4
- VERSION = "2.0.0"
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
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: 2024-01-08 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
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