auto_preload 0.1.1 → 0.1.2

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: 5b400e79944285da53bdd3246948248bdef10323e536761b38794fa7c774a085
4
- data.tar.gz: 222fcad81c801c6f33f1ae91e005b6402f87549b30e4f62d5e587b800e888f2d
3
+ metadata.gz: 83981d329237a816c396eeeb96058bf601531562846d5d365b664a25cbc683b6
4
+ data.tar.gz: 7090bcf8922549d45cd8410a98d09d841a17cdbd822dae21e1f69d8abd918890
5
5
  SHA512:
6
- metadata.gz: 46b10d83dde0c430ff36e0a4a0ac49daab14426240c696a396e7687e762ebed642a06a7a0a97feb08707552f6723174837a99c36bcfb29b92206f262f9c45afe
7
- data.tar.gz: 294bd08145cd0712de2899c2366b7e8c6783292cb837a1b397502410965cdb501e2c53198dcbd0a5814caecee87821be5d7b3cee9661193f0fc1cae3cca33e4a
6
+ metadata.gz: 61bb4dcb606073730f9edbf2d8888d9e28bdafaf2e22a409866a95bd771462ca83ce08a6c1828f14c65bb540d9f3e4bd3968e04bef3df40d23c49e3ab4e2b7f8
7
+ data.tar.gz: 4fff43c826eeb13787beb5f7b1c179c7d05045ea8090a91257c91264ff15f23144d8276137d0771a5f682952916cc8feeb2073b146b74397f1e6a267fe4d7316
@@ -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: |
data/.solargraph.yml ADDED
@@ -0,0 +1,25 @@
1
+ ---
2
+ include:
3
+ - "**/*.rb"
4
+ exclude:
5
+ - spec/**/*
6
+ - test/**/*
7
+ - vendor/**/*
8
+ - ".bundle/**/*"
9
+ require:
10
+ - activesupport
11
+ - activerecord
12
+ domains: []
13
+ reporters:
14
+ - rubocop
15
+ - require_not_found
16
+ - typecheck
17
+ formatter:
18
+ rubocop:
19
+ cops: safe
20
+ except: []
21
+ only: []
22
+ extra_args: []
23
+ require_paths: []
24
+ plugins: []
25
+ max_files: 5000
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ 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.1.2] - 2022-12-10
9
+
10
+ ### Added
11
+ - Documentation to all methods
12
+ - `solargraph` gem for development
13
+
8
14
  ## [0.1.1] - 2022-11-30
9
15
 
10
16
  ### Fixed
data/Gemfile CHANGED
@@ -12,6 +12,8 @@ gem "rspec", "~> 3.0"
12
12
 
13
13
  gem "rubocop", "~> 1.7"
14
14
 
15
+ gem "solargraph"
16
+
15
17
  gem "active_model_serializers", "~> 0.10"
16
18
  gem "simplecov"
17
19
  gem "yard"
@@ -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.1.2"
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.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mònade
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-30 00:00:00.000000000 Z
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -64,6 +64,7 @@ files:
64
64
  - ".gitignore"
65
65
  - ".rspec"
66
66
  - ".rubocop.yml"
67
+ - ".solargraph.yml"
67
68
  - CHANGELOG.md
68
69
  - Gemfile
69
70
  - LICENSE