auto_preload 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +2 -2
- data/.github/workflows/test.yml +1 -1
- data/CHANGELOG.md +16 -0
- data/auto_preload.gemspec +3 -3
- data/lib/auto_preload/active_record.rb +11 -0
- data/lib/auto_preload/adapters/active_record.rb +2 -0
- data/lib/auto_preload/adapters/serializer.rb +5 -0
- data/lib/auto_preload/adapters.rb +1 -0
- data/lib/auto_preload/config.rb +1 -1
- data/lib/auto_preload/resolver.rb +6 -1
- data/lib/auto_preload/version.rb +2 -1
- data/lib/auto_preload.rb +8 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4ea3f1c85774246755120cb7697b3e8340562753aad2ea1161aad16d412221b
|
4
|
+
data.tar.gz: ff06dc6aafa7dfa3209a40b88322a6b07b2ce7e5d95cb1c78cbf66d7461a343a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1e66474138847aa04278a2295c67e5051eea4ffb11868badb64a020fd508bcb0bc2d72bc5cc66997d5cad3f862e558f40499112a1cf266d1107eecd6ef7c928
|
7
|
+
data.tar.gz: 762af4554836aef3df571b5977c60d2a37236ae8c4aee7fa0a0a74d4c60626e933df2057b88020ac6f741af15dfda1e935ab9478c1de29cf16085247309be5fb
|
data/.github/workflows/test.yml
CHANGED
@@ -7,7 +7,7 @@ jobs:
|
|
7
7
|
matrix:
|
8
8
|
os: [ubuntu-latest, macos-latest]
|
9
9
|
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
10
|
-
ruby: [
|
10
|
+
ruby: ['3.0', 3.1, 3.2, 3.3, head, truffleruby]
|
11
11
|
runs-on: ${{ matrix.os }}
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v2
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.2.0] - 2025-01-20
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Support for Rails 8
|
12
|
+
|
13
|
+
### Removed
|
14
|
+
- Support for Rails 6
|
15
|
+
- Dropped support for ruby 2.7
|
16
|
+
- gem `solargraph`
|
17
|
+
|
18
|
+
## [0.1.2] - 2022-12-10
|
19
|
+
|
20
|
+
### Added
|
21
|
+
- Documentation to all methods
|
22
|
+
- `solargraph` gem for development
|
23
|
+
|
8
24
|
## [0.1.1] - 2022-11-30
|
9
25
|
|
10
26
|
### Fixed
|
data/auto_preload.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.description = "A gem to run nested preloads/includes from string."
|
15
15
|
spec.homepage = "https://github.com/monade/auto_preload"
|
16
16
|
spec.license = "MIT"
|
17
|
-
spec.required_ruby_version = ">=
|
17
|
+
spec.required_ruby_version = ">= 3.0"
|
18
18
|
|
19
19
|
spec.metadata["homepage_uri"] = spec.homepage
|
20
20
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
33
|
-
spec.add_dependency "activerecord", [">=
|
34
|
-
spec.add_dependency "activesupport", [">=
|
33
|
+
spec.add_dependency "activerecord", [">= 6", "< 9"]
|
34
|
+
spec.add_dependency "activesupport", [">= 6", "< 9"]
|
35
35
|
|
36
36
|
# For more information and examples about making a new gem, checkout our
|
37
37
|
# guide at: https://bundler.io/guides/creating_gem.html
|
@@ -1,10 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module AutoPreload
|
4
|
+
# Extensions to ActiveRecord::Base
|
4
5
|
module ActiveRecord
|
5
6
|
extend ActiveSupport::Concern
|
6
7
|
|
7
8
|
included do
|
9
|
+
# @param [String, Array<String>] inclusions
|
10
|
+
# @param [Hash] options
|
11
|
+
# @return [ActiveRecord::Relation]
|
8
12
|
scope :auto_includes, lambda { |inclusions, options = {}|
|
9
13
|
if inclusions.present?
|
10
14
|
resolved = Resolver.new(options).resolve(self, inclusions)
|
@@ -13,6 +17,9 @@ module AutoPreload
|
|
13
17
|
self
|
14
18
|
end
|
15
19
|
}
|
20
|
+
# @param [String, Array<String>] inclusions
|
21
|
+
# @param [Hash] options
|
22
|
+
# @return [ActiveRecord::Relation]
|
16
23
|
scope :auto_preload, lambda { |inclusions, options = {}|
|
17
24
|
if inclusions.present?
|
18
25
|
resolved = Resolver.new(options).resolve(self, inclusions)
|
@@ -21,6 +28,9 @@ module AutoPreload
|
|
21
28
|
self
|
22
29
|
end
|
23
30
|
}
|
31
|
+
# @param [String, Array<String>] inclusions
|
32
|
+
# @param [Hash] options
|
33
|
+
# @return [ActiveRecord::Relation]
|
24
34
|
scope :auto_eager_load, lambda { |inclusions, options = {}|
|
25
35
|
if inclusions.present?
|
26
36
|
resolved = Resolver.new(options).resolve(self, inclusions)
|
@@ -30,6 +40,7 @@ module AutoPreload
|
|
30
40
|
end
|
31
41
|
}
|
32
42
|
|
43
|
+
# @return [nil, Array<Symbol>]
|
33
44
|
class_attribute :auto_preloadable
|
34
45
|
end
|
35
46
|
end
|
@@ -4,6 +4,8 @@ module AutoPreload
|
|
4
4
|
module Adapters
|
5
5
|
# This class takes a model and finds all the preloadable associations.
|
6
6
|
class ActiveRecord
|
7
|
+
# @param [ActiveRecord::Base] model
|
8
|
+
# @return [Array<ActiveRecord::Reflection>] The preloadable associations.
|
7
9
|
def resolve_preloadables(model, _options = {})
|
8
10
|
if model.auto_preloadable
|
9
11
|
model.auto_preloadable.map { |w| model.reflect_on_association(w) }.compact
|
@@ -24,6 +24,11 @@ module AutoPreload
|
|
24
24
|
end.compact
|
25
25
|
end
|
26
26
|
|
27
|
+
# @param model [ActiveRecord::Base]
|
28
|
+
# @param options [Hash]
|
29
|
+
# @option options [Boolean] :root
|
30
|
+
# @option options [ActiveModel::Serializer] :serializer
|
31
|
+
# @return [ActiveModel::Serializer]
|
27
32
|
def resolve_serializer(model, options = {})
|
28
33
|
if options[:root]
|
29
34
|
options[:serializer] || ActiveModel::Serializer.serializer_for(model)
|
data/lib/auto_preload/config.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module AutoPreload
|
4
4
|
# This class handles the gem configurations.
|
5
5
|
class Config
|
6
|
-
# @
|
6
|
+
# @return [AutoPreload::Adapters::ActiveRecord, AutoPreload::Adapters::Serializer] The adapter to use.
|
7
7
|
attr_writer :adapter
|
8
8
|
|
9
9
|
# @return [AutoPreload::Adapters::ActiveRecord, AutoPreload::Adapters::Serializer] The adapter to use.
|
@@ -3,8 +3,13 @@
|
|
3
3
|
module AutoPreload
|
4
4
|
# This class parses a string in the format "articles,comments" and returns an array of symbols.
|
5
5
|
class Resolver
|
6
|
+
# Default max number of iterations
|
7
|
+
# @return [Integer]
|
6
8
|
MAX_ITERATIONS = 100
|
7
9
|
|
10
|
+
# @param options [Hash]
|
11
|
+
# @option options [Integer] :max_iterations
|
12
|
+
# @option options [AutoPreload::Adapters::ActiveRecord, AutoPreload::Adapters::Serializer] :adapter
|
8
13
|
def initialize(options = {})
|
9
14
|
@iterations = 0
|
10
15
|
@options = options
|
@@ -43,7 +48,7 @@ module AutoPreload
|
|
43
48
|
objects.present? ? (symbols << objects) : symbols
|
44
49
|
end
|
45
50
|
|
46
|
-
# @param
|
51
|
+
# @param objects [Array<Hash>]
|
47
52
|
# @return [Hash]
|
48
53
|
def merge(objects)
|
49
54
|
objects.reduce({}) do |result, object|
|
data/lib/auto_preload/version.rb
CHANGED
data/lib/auto_preload.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require "active_support"
|
4
4
|
require "active_record"
|
5
5
|
|
6
|
+
# Provides methods to run `preload`/`includes`/`eager_load` on your model
|
7
|
+
# from a JSON::API include string.
|
6
8
|
module AutoPreload
|
7
9
|
extend ActiveSupport::Autoload
|
8
10
|
|
@@ -11,13 +13,18 @@ module AutoPreload
|
|
11
13
|
autoload :Resolver
|
12
14
|
autoload :Config
|
13
15
|
|
16
|
+
# @yield [AutoPreload::Config]
|
17
|
+
# @return [AutoPreload::Config]
|
14
18
|
def self.configure
|
15
19
|
yield(config)
|
16
20
|
end
|
17
21
|
|
22
|
+
# @return [AutoPreload::Config]
|
18
23
|
def self.config
|
19
24
|
@config ||= Config.new
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
23
|
-
|
28
|
+
# rubocop:disable Lint/SendWithMixinArgument
|
29
|
+
ActiveRecord::Base.send(:include, AutoPreload::ActiveRecord)
|
30
|
+
# rubocop:enable Lint/SendWithMixinArgument
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_preload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mònade
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,40 +16,40 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '9'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '9'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '6'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '9'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '6'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '9'
|
53
53
|
description: A gem to run nested preloads/includes from string.
|
54
54
|
email:
|
55
55
|
- team@monade.io
|
@@ -85,7 +85,7 @@ metadata:
|
|
85
85
|
homepage_uri: https://github.com/monade/auto_preload
|
86
86
|
source_code_uri: https://github.com/monade/auto_preload
|
87
87
|
changelog_uri: https://github.com/monade/auto_preload/CHANGELOG.md
|
88
|
-
post_install_message:
|
88
|
+
post_install_message:
|
89
89
|
rdoc_options: []
|
90
90
|
require_paths:
|
91
91
|
- lib
|
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.0'
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
99
|
- - ">="
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubygems_version: 3.2.33
|
104
|
-
signing_key:
|
104
|
+
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: A gem to run nested preloads/includes from string.
|
107
107
|
test_files: []
|