uberloader 0.1.0 → 0.3.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: 18172000e1265e1e5a71cf636dc7589a9a66ea126cbf4284657b9470b4e056eb
4
- data.tar.gz: 5ed598b20223993795bd34cbeb2dacbe0a972e1c901d17598240b797b3db05bc
3
+ metadata.gz: 0d7a5fee540e1317f8a7799b38c2b2b4a28fdf86381ca435d54b8a1cca9ef48a
4
+ data.tar.gz: a6703c0941ebc666faad5887ba3cd823ea0a31c689a206d77ea5db1d2cec4424
5
5
  SHA512:
6
- metadata.gz: d217e55a50c48408823c1415a7413f62645e4384e7000ef30cc6ca2764298820e86d8cd8222738f64a4fa9a3f65fe173aca69ef2e2c06f08adfa2b1f53286a3a
7
- data.tar.gz: c787e50e4d5e89cfd0673aa5f52e6634bc91d92396001f5b559b47fc0f080d271af2e6cb9ca45cca2a59632d6b7616bccaebc753b0669d52ca8583036224ce46
6
+ metadata.gz: d2dd6919e9074c17bd039d635284d7fef853f8844a14b51e9ee5e664aa5f3e22047b525e3118b61523e7eb5f523868e004a4082e1bb56998a825bb1d520d4081
7
+ data.tar.gz: ae5acc63757518f9d2d1868db983bb56952e8719ef091a0159850d74d1599a506293391a6ce4888b32f004be4f947042877c455d8d6109b2487b67290146232a
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Uberloader
2
2
 
3
- Uberloader is a new way of preloading associations in ActiveRecord. Nested preloads use blocks. Custom scopes may be given as args and/or as method calls inside a block.
3
+ Uberloader is a new way of preloading associations in ActiveRecord. It works like `preload`, but with the following changes:
4
+
5
+ * Custom scopes may be given.
6
+ * Nested preloads use blocks.
4
7
 
5
8
  ```ruby
6
9
  widgets = Widget
@@ -14,6 +17,7 @@ widgets = Widget
14
17
  # and their subparts, using a custom scope
15
18
  u.uberload(:subparts) do
16
19
  u.scope my_subparts_scope_helper
20
+ u.scope Subpart.where(kind: params[:sub_kinds]) if params[:sub_kinds]&.any?
17
21
 
18
22
  u.uberload(:foo) do
19
23
  u.uberload(:bar)
@@ -22,9 +26,11 @@ widgets = Widget
22
26
  end
23
27
  ```
24
28
 
25
- ## Status
29
+ Install with Bundler:
26
30
 
27
- Uberloader is an attempt to bring [ideas from OccamsRecord](https://github.com/jhollinger/occams-record/?tab=readme-ov-file#advanced-eager-loading) deeper into ActiveRecord, making them easier to use in existing applications. It's usable in production, but **note that it monkeypatches** `ActiveRecord::Relation#preload_associations`. YMMV if other gems monkeypatch this method.
31
+ ```bash
32
+ bundle add uberloader
33
+ ```
28
34
 
29
35
  ## Interaction with preload and includes
30
36
 
@@ -36,6 +42,14 @@ widgets = Widget
36
42
  .uberload(:parts, scope: Part.order(:name))
37
43
  ```
38
44
 
45
+ ## On Monkeypatches and Safety
46
+
47
+ Regretably, none of this is possible without monkeypatching `ActiveRecord::Relation`'s non-public `preload_associations` method. While small, the patch has no guarntee of working in the next minor, or even tiny, patch.
48
+
49
+ To assess its stability over time, I ran Uberloader's unit tests against the full matrix of (supported) ActiveRecord and Uberloader versions. They passed consistently, but with predictable clusters of failures around pre-release and X.0.0 versions.
50
+
51
+ I will keep these tests running daily, and against this project's `main` branch as well. [You can find the link to the results here](https://github.com/jhollinger/uberloader/blob/docs/VERSION_COMPATIBILITY.md). If something breaks, I'll try to fix it. If we're lucky, maybe this behavior could get _into_ Rails itself someday...
52
+
39
53
  ## Testing
40
54
 
41
55
  Testing is fully scripted under the `bin/` directory. Appraisal is used to test against various ActiveRecord versions, and Docker or Podman is used to test against various Ruby versions. The combinations to test are defined in [test/matrix](https://github.com/jhollinger/uberloader/blob/main/test/matrix).
@@ -61,3 +75,18 @@ bin/test ruby-3.3 ar-7.1 sqlite3 N=test_add_preload_values
61
75
  # Use podman
62
76
  PODMAN=1 bin/testall
63
77
  ```
78
+
79
+ ### Version compatibility testing
80
+
81
+ ```bash
82
+ # Test all combinations of (supported) ActiveRecord versions against all uberloader versions
83
+ bin/testall-compatibility
84
+
85
+ # Output the results as a Markdown table
86
+ bin/generate-version-test-table
87
+
88
+ # Run tests for specific versions
89
+ # Appraisal ActiveRecord Uberloader
90
+ bin/test-compatibility 7.1 7.1.3.2 0.1.0
91
+ bin/test-compatibility 7.1 7.1.3.2 HEAD
92
+ ```
@@ -0,0 +1,9 @@
1
+ module Uberloader
2
+ module Preloader
3
+ def self.call(records, association, scope = nil)
4
+ ::ActiveRecord::Associations::Preloader
5
+ .new(records: records, associations: association, scope: scope)
6
+ .call
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Uberloader
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
data/lib/uberloader.rb CHANGED
@@ -9,6 +9,7 @@ module Uberloader
9
9
 
10
10
  autoload :Preloader,
11
11
  case ActiveRecord::VERSION::MAJOR
12
+ when 8 then 'uberloader/preloader/v8'
12
13
  when 7 then 'uberloader/preloader/v7'
13
14
  when 6 then 'uberloader/preloader/v6'
14
15
  else raise "Unsupported ActiveRecord version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uberloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-22 00:00:00.000000000 Z
11
+ date: 2024-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '6.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.2'
22
+ version: '8.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '6.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.2'
32
+ version: '8.1'
33
33
  description: Customizable SQL when preloading in ActiveRecord
34
34
  email: jordan.hollinger@gmail.com
35
35
  executables: []
@@ -42,6 +42,7 @@ files:
42
42
  - lib/uberloader/context.rb
43
43
  - lib/uberloader/preloader/v6.rb
44
44
  - lib/uberloader/preloader/v7.rb
45
+ - lib/uberloader/preloader/v8.rb
45
46
  - lib/uberloader/query_methods.rb
46
47
  - lib/uberloader/uberload.rb
47
48
  - lib/uberloader/version.rb