esse-active_record 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/ci/Gemfile.rails-5.2.lock +1 -1
- data/ci/Gemfile.rails-6.0.lock +1 -1
- data/ci/Gemfile.rails-6.1.lock +1 -1
- data/ci/Gemfile.rails-7.0.lock +1 -1
- data/ci/Gemfile.rails-7.1.lock +1 -1
- data/lib/esse/active_record/collection.rb +35 -8
- data/lib/esse/active_record/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 412017405772bf674a32c43510c0fdd15c0d1ac9de09357e523aa87c7d8bb0ab
|
4
|
+
data.tar.gz: 869613dcb7b78c03097989dbeb2d565dc790b119043d7a1a7e7183ccdca1ba5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3247f133ad930ea4ac1e69d3a242113c7ac26bc8de33737f350321fbe3b9de01ec21648310ff1b7c7ba326bca763107b4c313c663ae82686bb24da7d47e1cd3
|
7
|
+
data.tar.gz: 63593435b2cea9284e530351398960f5b73d2aceaad6cb336b30cec90e11cb419b4ad7a55a80265a91cb5b2b9c7704572758129d135ddc5f611e0f98f1be0de6
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## 0.3.7 - 2024-08-05
|
8
|
+
* Add `connected_to` to the collection for custom connection handling
|
9
|
+
|
10
|
+
## 0.0.1
|
11
|
+
The first release of the esse-active_record plugin
|
12
|
+
* Added: Initial implementation of the plugin
|
data/Gemfile.lock
CHANGED
data/ci/Gemfile.rails-5.2.lock
CHANGED
data/ci/Gemfile.rails-6.0.lock
CHANGED
data/ci/Gemfile.rails-6.1.lock
CHANGED
data/ci/Gemfile.rails-7.0.lock
CHANGED
data/ci/Gemfile.rails-7.1.lock
CHANGED
@@ -21,6 +21,12 @@ module Esse
|
|
21
21
|
class_attribute :batch_contexts
|
22
22
|
self.batch_contexts = {}
|
23
23
|
|
24
|
+
# Connects to a database or role (ex writing, reading, or another custom role) for the collection query
|
25
|
+
# @param [Symbol] role The role to connect to
|
26
|
+
# @param [Symbol] shard The shard to connect to
|
27
|
+
class_attribute :connect_with
|
28
|
+
self.connect_with = nil
|
29
|
+
|
24
30
|
class << self
|
25
31
|
def inspect
|
26
32
|
return super unless self < Esse::ActiveRecord::Collection
|
@@ -40,6 +46,7 @@ module Esse
|
|
40
46
|
|
41
47
|
subclass.scopes = scopes.dup
|
42
48
|
subclass.batch_contexts = batch_contexts.dup
|
49
|
+
subclass.connect_with = connect_with&.dup
|
43
50
|
end
|
44
51
|
|
45
52
|
def scope(name, proc = nil, override: false, &block)
|
@@ -57,6 +64,10 @@ module Esse
|
|
57
64
|
|
58
65
|
batch_contexts[name.to_sym] = proc
|
59
66
|
end
|
67
|
+
|
68
|
+
def connected_to(**kwargs)
|
69
|
+
self.connect_with = kwargs
|
70
|
+
end
|
60
71
|
end
|
61
72
|
|
62
73
|
attr_reader :start, :finish, :batch_size, :params
|
@@ -74,23 +85,29 @@ module Esse
|
|
74
85
|
end
|
75
86
|
|
76
87
|
def each
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
88
|
+
with_connection do
|
89
|
+
dataset.find_in_batches(**batch_options) do |rows|
|
90
|
+
kwargs = params.dup
|
91
|
+
self.class.batch_contexts.each do |name, proc|
|
92
|
+
kwargs[name] = proc.call(rows, **params)
|
93
|
+
end
|
94
|
+
yield(rows, **kwargs)
|
81
95
|
end
|
82
|
-
yield(rows, **kwargs)
|
83
96
|
end
|
84
97
|
end
|
85
98
|
|
86
99
|
def each_batch_ids
|
87
|
-
|
88
|
-
|
100
|
+
with_connection do
|
101
|
+
dataset.select(:id).except(:includes, :preload, :eager_load).find_in_batches(**batch_options) do |rows|
|
102
|
+
yield(rows.map(&:id))
|
103
|
+
end
|
89
104
|
end
|
90
105
|
end
|
91
106
|
|
92
107
|
def count
|
93
|
-
|
108
|
+
with_connection do
|
109
|
+
dataset.except(:includes, :preload, :eager_load, :group, :order, :limit, :offset).count
|
110
|
+
end
|
94
111
|
end
|
95
112
|
alias_method :size, :count
|
96
113
|
|
@@ -127,6 +144,16 @@ module Esse
|
|
127
144
|
|
128
145
|
protected
|
129
146
|
|
147
|
+
def with_connection
|
148
|
+
if self.class.connect_with&.any?
|
149
|
+
::ActiveRecord::Base.connected_to(**self.class.connect_with) do
|
150
|
+
yield
|
151
|
+
end
|
152
|
+
else
|
153
|
+
yield
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
130
157
|
def batch_options
|
131
158
|
{
|
132
159
|
batch_size: batch_size
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esse-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos G. Zimmermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: esse
|
@@ -206,6 +206,7 @@ extensions: []
|
|
206
206
|
extra_rdoc_files: []
|
207
207
|
files:
|
208
208
|
- ".rubocop.yml"
|
209
|
+
- CHANGELOG.md
|
209
210
|
- Gemfile
|
210
211
|
- Gemfile.lock
|
211
212
|
- LICENSE.txt
|