auto_preload 0.1.1 → 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: 5b400e79944285da53bdd3246948248bdef10323e536761b38794fa7c774a085
4
- data.tar.gz: 222fcad81c801c6f33f1ae91e005b6402f87549b30e4f62d5e587b800e888f2d
3
+ metadata.gz: b4ea3f1c85774246755120cb7697b3e8340562753aad2ea1161aad16d412221b
4
+ data.tar.gz: ff06dc6aafa7dfa3209a40b88322a6b07b2ce7e5d95cb1c78cbf66d7461a343a
5
5
  SHA512:
6
- metadata.gz: 46b10d83dde0c430ff36e0a4a0ac49daab14426240c696a396e7687e762ebed642a06a7a0a97feb08707552f6723174837a99c36bcfb29b92206f262f9c45afe
7
- data.tar.gz: 294bd08145cd0712de2899c2366b7e8c6783292cb837a1b397502410965cdb501e2c53198dcbd0a5814caecee87821be5d7b3cee9661193f0fc1cae3cca33e4a
6
+ metadata.gz: b1e66474138847aa04278a2295c67e5051eea4ffb11868badb64a020fd508bcb0bc2d72bc5cc66997d5cad3f862e558f40499112a1cf266d1107eecd6ef7c928
7
+ data.tar.gz: 762af4554836aef3df571b5977c60d2a37236ae8c4aee7fa0a0a74d4c60626e933df2057b88020ac6f741af15dfda1e935ab9478c1de29cf16085247309be5fb
@@ -16,9 +16,9 @@ jobs:
16
16
  steps:
17
17
  - uses: actions/checkout@v3
18
18
  - name: Set up Ruby 3.0
19
- uses: actions/setup-ruby@v1
19
+ uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: 3.0.x
21
+ ruby-version: '3.0'
22
22
 
23
23
  - name: Publish to GPR
24
24
  run: |
@@ -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: [2.7, '3.0', 3.1, head, truffleruby]
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 = ">= 2.7"
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", [">= 5", "< 8"]
34
- spec.add_dependency "activesupport", [">= 5", "< 8"]
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)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutoPreload
4
+ # This module contains the adapters used to parse JSON::API include strings.
4
5
  module Adapters
5
6
  extend ActiveSupport::Autoload
6
7
 
@@ -3,7 +3,7 @@
3
3
  module AutoPreload
4
4
  # This class handles the gem configurations.
5
5
  class Config
6
- # @attr_writr [AutoPreload::Adapters::ActiveRecord, AutoPreload::Adapters::Serializer] adapter The adapter to use.
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 list [Array<Hash>]
51
+ # @param objects [Array<Hash>]
47
52
  # @return [Hash]
48
53
  def merge(objects)
49
54
  objects.reduce({}) do |result, object|
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutoPreload
4
- VERSION = "0.1.1"
4
+ # @return [String] The version of the gem.
5
+ VERSION = "0.2.0"
5
6
  end
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
- ActiveRecord::Base.include AutoPreload::ActiveRecord
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.1.1
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: 2022-11-30 00:00:00.000000000 Z
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: '5'
19
+ version: '6'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8'
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: '5'
29
+ version: '6'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8'
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: '5'
39
+ version: '6'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '8'
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: '5'
49
+ version: '6'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '8'
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: '2.7'
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: []