type_balancer_rails 0.1.3 → 0.2.2
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 +11 -0
- data/lib/type_balancer/rails/collection_methods.rb +11 -10
- data/lib/type_balancer/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e10b44bca0db1b7b70b27edebe34fff8f093cc433a7e210cf5fa73d7e46e1def
|
4
|
+
data.tar.gz: d51be3f1504a88ba8c4823ce9050600bcf195990de2ff7a0e2e5f94f40553ea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5255e44be19018af84f4189e66c28a96aa32a9740831002007dff1700123dad612fda942412fa4ecd650f12aa713bf6fad6a241ef9b2b55305e926eeffd4512
|
7
|
+
data.tar.gz: c66e8ed1a360d73bb047baa7549f5722e7d4fd98884830258f23bb326eabf803716db3dccfe9fc8bfa56740a7cc369fc68c919865a3ae12954c46eb455b624de
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.2] - 2024-04-27
|
4
|
+
|
5
|
+
- Version sync release: Ensures the gem version and git tag match after a previous mismatch (v0.2.1 tag pointed to v0.2.0 code). No code changes from 0.2.1.
|
6
|
+
|
7
|
+
## [0.2.0] - 2024-04-27
|
8
|
+
|
9
|
+
- Refactored `balance_by_type` to only send `id` and type field to TypeBalancer for efficiency and clarity
|
10
|
+
- Ensured robust ordering of returned records based on balanced ids (supports flat and nested balancer output)
|
11
|
+
- Full TDD coverage for all new and refactored logic (unit and integration tests)
|
12
|
+
- Added GitHub Actions workflow for automated gem releases on tag push
|
13
|
+
|
3
14
|
## [0.1.0] - 2025-04-10
|
4
15
|
|
5
16
|
- Initial release
|
@@ -24,7 +24,11 @@ module TypeBalancer
|
|
24
24
|
return empty_relation if records.empty?
|
25
25
|
|
26
26
|
type_field = fetch_type_field(options)
|
27
|
-
|
27
|
+
# Map to array of hashes with only id and type
|
28
|
+
id_and_type_hashes = records.map do |record|
|
29
|
+
{ id: record.id, type: record.send(type_field) }
|
30
|
+
end
|
31
|
+
balanced = TypeBalancer.balance(id_and_type_hashes, type_field: :type)
|
28
32
|
return empty_relation if balanced.nil?
|
29
33
|
|
30
34
|
paged = apply_pagination(balanced, options)
|
@@ -43,15 +47,12 @@ module TypeBalancer
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def build_result(balanced)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
self.class.new(balanced)
|
54
|
-
end
|
50
|
+
# Flatten in case balanced is a nested array
|
51
|
+
ids = balanced.flatten.map { |h| h[:id] }
|
52
|
+
# Map back to original records (works for both AR and TestRelation)
|
53
|
+
records_by_id = to_a.index_by(&:id)
|
54
|
+
ordered = ids.map { |id| records_by_id[id] }
|
55
|
+
self.class.new(ordered)
|
55
56
|
end
|
56
57
|
|
57
58
|
def empty_relation
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: type_balancer_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Smith
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.4.19
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Rails integration for type_balancer
|