type_balancer_rails 0.1.3 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ebd00e75d4c63af53f5be038f01f920eb6e65dcf3c91ae079a10b20435d62ce
4
- data.tar.gz: 67d328f6ae917d27f88455dce176073dd8da0cf8dd7bb2be460c886c7a56086f
3
+ metadata.gz: b638243aa1d2aa29637bf2696d7ce7e8625bed13c17bb73122ddb0d9f1356e6a
4
+ data.tar.gz: 4ac1aa33b569d4da75786e0a8a14ae35a5c2fb20fd3d86cdb1637ef630719809
5
5
  SHA512:
6
- metadata.gz: 4a82e84484c322cd4ee02c92950cf3235daa989b21097c845a5e41a454084afe883ee15444729992e7a63b59318508dbd7f89a15d1abe3d371f8de2cc1e1c551
7
- data.tar.gz: e427b4224fbed0bd83dcda7dd2ce97683dc1c7df54a2fb673ce15b9d545ee029f87637fb5a8cff685cb7570f7d0e7aeaf3c82e0a5466906773326a2d9d794486
6
+ metadata.gz: 7fd6d6bcd22be7a11c2bd9d5181253c31f0df27966d7c4a68258c3a7e9b6690a42c4e7e4320d2ed543c4155caf2ae7a79e361202bf37661f2f6f6282f98ff29f
7
+ data.tar.gz: 22503105265aa58554a3e839d431ca3e4ac8d15f39c2b90a3099175cdd383bbdf4deb0982c97886a50ea6da71057258e308e8e4467ced627980c689dfd205f85
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-04-27
4
+
5
+ - Refactored `balance_by_type` to only send `id` and type field to TypeBalancer for efficiency and clarity
6
+ - Ensured robust ordering of returned records based on balanced ids (supports flat and nested balancer output)
7
+ - Full TDD coverage for all new and refactored logic (unit and integration tests)
8
+ - Added GitHub Actions workflow for automated gem releases on tag push
9
+
3
10
  ## [0.1.0] - 2025-04-10
4
11
 
5
12
  - 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
- balanced = TypeBalancer.balance(records, type_field: type_field)
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
- if klass.respond_to?(:where) && klass != TestModel
47
- ids = balanced.map(&:id)
48
- results = klass.where(id: ids).to_a
49
- results_by_id = results.index_by(&:id)
50
- ordered = ids.map { |id| results_by_id[id] }
51
- self.class.new(ordered)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TypeBalancer
4
4
  module Rails
5
- VERSION = '0.1.3'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
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.1.3
4
+ version: 0.2.0
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.5.18
118
+ rubygems_version: 3.4.19
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Rails integration for type_balancer