goldiloader 0.0.11 → 0.0.12

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
  SHA1:
3
- metadata.gz: 526a23489a3e8b11cc8f0f54bbad2d172aab998c
4
- data.tar.gz: 65d84a61f5f1d7c1efee2ac66e46b4661cdbc8ac
3
+ metadata.gz: 9e841dae40175e8b5f4dfff64bafa99235d12a7c
4
+ data.tar.gz: 5c9f9b0e4e39c0dc3ceab77bcf7cd00f7f38c96f
5
5
  SHA512:
6
- metadata.gz: 7b689413962ae9ae86dcec25f2a27a3472f7c406a3b932f7b20f4f92dade3900c8a6d20e5eca79f7e6762c886d5520d1512904479aa28f428b3e519983b2ac9c
7
- data.tar.gz: 363b20372285117f68e22281b823586ca0136417b0449cf94f47a345ecad372e6cc2f3d09336911d476d4c15b080bdc0c421d91074fe78f16c0c472822cd8b18
6
+ metadata.gz: e2829c6d011ecdbf060867f1fe302beff76a831ad966017cbe0e581c914297c38f53f181f167736a9bd04d3a9d0ba92f3e25e24f7e6346270b1f5dfb451e6754
7
+ data.tar.gz: b9d871721fdc9385ebef66365b304aacc0d75facb69f2edbd349b86539c15507255b03c083b5ba89334d972f05fe1d2cec2efb899694eaa308913f88114d425c
@@ -28,10 +28,10 @@ ActiveRecord::Base.send(:include, Goldiloader::AutoIncludableModel)
28
28
 
29
29
  ActiveRecord::Relation.class_eval do
30
30
 
31
- def exec_queries_with_auto_include
32
- return exec_queries_without_auto_include if loaded?
31
+ def exec_queries_with_auto_include(&block)
32
+ return exec_queries_without_auto_include(&block) if loaded?
33
33
 
34
- models = exec_queries_without_auto_include
34
+ models = exec_queries_without_auto_include(&block)
35
35
  Goldiloader::AutoIncludeContext.register_models(models, eager_load_values)
36
36
  models
37
37
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Goldiloader
4
- VERSION = '0.0.11'.freeze
4
+ VERSION = '0.0.12'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goldiloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Turkel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-25 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -155,15 +155,7 @@ executables: []
155
155
  extensions: []
156
156
  extra_rdoc_files: []
157
157
  files:
158
- - ".gitignore"
159
- - ".rspec"
160
- - ".travis.yml"
161
- - CHANGELOG.md
162
- - Gemfile
163
158
  - LICENSE.txt
164
- - README.md
165
- - Rakefile
166
- - goldiloader.gemspec
167
159
  - lib/goldiloader.rb
168
160
  - lib/goldiloader/active_record_patches.rb
169
161
  - lib/goldiloader/association_info.rb
@@ -172,11 +164,6 @@ files:
172
164
  - lib/goldiloader/auto_include_context.rb
173
165
  - lib/goldiloader/compatibility.rb
174
166
  - lib/goldiloader/version.rb
175
- - spec/db/database.yml
176
- - spec/db/schema.rb
177
- - spec/goldiloader/auto_include_context_spec.rb
178
- - spec/goldiloader/goldiloader_spec.rb
179
- - spec/spec_helper.rb
180
167
  homepage: https://github.com/salsify/goldiloader
181
168
  licenses:
182
169
  - MIT
@@ -197,13 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
184
  version: '0'
198
185
  requirements: []
199
186
  rubyforge_project:
200
- rubygems_version: 2.5.1
187
+ rubygems_version: 2.6.10
201
188
  signing_key:
202
189
  specification_version: 4
203
190
  summary: Automatic Rails association eager loading
204
- test_files:
205
- - spec/db/database.yml
206
- - spec/db/schema.rb
207
- - spec/goldiloader/auto_include_context_spec.rb
208
- - spec/goldiloader/goldiloader_spec.rb
209
- - spec/spec_helper.rb
191
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- *.gem
2
- *.iml
3
- *.rbc
4
- .bundle
5
- .config
6
- .idea/
7
- .yardoc
8
- Gemfile.lock
9
- InstalledFiles
10
- _yardoc
11
- coverage
12
- doc/
13
- lib/bundler/man
14
- log/
15
- pkg
16
- rdoc
17
- spec/reports
18
- test/tmp
19
- test/version_tmp
20
- tmp
21
- .ruby-version
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- env:
4
- - RAILS_VERSION="~> 3.2.22.2" JRUBY_OPTS="$JRUBY_OPTS --debug"
5
- - RAILS_VERSION="~> 4.0.13" JRUBY_OPTS="$JRUBY_OPTS --debug"
6
- - RAILS_VERSION="~> 4.1.16" JRUBY_OPTS="$JRUBY_OPTS --debug"
7
- - RAILS_VERSION="~> 4.2.7.1" JRUBY_OPTS="$JRUBY_OPTS --debug"
8
- - RAILS_VERSION="~> 5.0.1" JRUBY_OPTS="$JRUBY_OPTS --debug"
9
- rvm:
10
- - 1.9.3
11
- - 2.0.0
12
- - 2.1.10
13
- - 2.2.6
14
- - 2.3.3
15
- - jruby-19mode
16
- - jruby-9.1.7.0
17
- matrix:
18
- exclude:
19
- - rvm: 1.9.3
20
- env: RAILS_VERSION="~> 5.0.1" JRUBY_OPTS="$JRUBY_OPTS --debug"
21
- - rvm: 2.0.0
22
- env: RAILS_VERSION="~> 5.0.1" JRUBY_OPTS="$JRUBY_OPTS --debug"
23
- - rvm: 2.1.10
24
- env: RAILS_VERSION="~> 5.0.1" JRUBY_OPTS="$JRUBY_OPTS --debug"
25
- - rvm: jruby-19mode
26
- env: RAILS_VERSION="~> 5.0.1" JRUBY_OPTS="$JRUBY_OPTS --debug"
27
- - rvm: jruby-9.1.7.0
28
- env: RAILS_VERSION="~> 5.0.1" JRUBY_OPTS="$JRUBY_OPTS --debug"
data/CHANGELOG.md DELETED
@@ -1,67 +0,0 @@
1
- # Changelog
2
-
3
- ### 0.0.11 (unreleased)
4
- * Fix [issue 34](https://github.com/salsify/goldiloader/issues/34) - HABTM associations now honor
5
- the auto_include option.
6
- * Fix [issue 39](https://github.com/salsify/goldiloader/issues/39) - `CollectionProxy#exists?` should return false
7
- for a new model's association with no values.
8
-
9
- ### 0.0.10
10
- * Fix [issue 13](https://github.com/salsify/goldiloader/issues/13) - Eager load associations with unscope
11
- in Rails 4.1.9+ now that the underlying Rails bug has been fixed.
12
- * Fix [issue 11](https://github.com/salsify/goldiloader/issues/11) - Eager load associations with joins in
13
- Rails 4.2+ now that the underlying Rails bug has been fixed.
14
- * Initial support for Rails 5. There are no known issues but see
15
- [issue 27](https://github.com/salsify/goldiloader/issues/27) for remaining tasks.
16
- * MRI 2.3.0 support.
17
- * JRuby 9000 support.
18
-
19
- ### 0.0.9
20
- * Merge [pull request](https://github.com/salsify/goldiloader/pull/24) - Optimization: Cache compatibility
21
- checks. **Thanks Jonathan Calvert!**
22
-
23
- ### 0.0.8
24
- * Fix [issue 23](https://github.com/salsify/goldiloader/issues/23) - Handle polymorphic belongs_to
25
- associations in Rails 4 that have a mix of non-nil and nil values.
26
-
27
- ### 0.0.7
28
- * Fix [issue 20](https://github.com/salsify/goldiloader/issues/20) by not auto-eager loading
29
- associations that are instance dependent. Eager loading these associations produces potentially
30
- incorrect results and leads to a deprecation warning in Rails 4.2.
31
- * Fix [issue 21](https://github.com/salsify/goldiloader/issues/21) - Handle explicit eager loads
32
- of singular associations that are nil.
33
- * Rails 4.2 support.
34
-
35
- ### 0.0.6
36
- * Workaround [issue 16](https://github.com/salsify/goldiloader/issues/16) by not auto-eager loading
37
- has_and_belongs_to_many associations with a uniq in Rails 3.2 since Rails doesn't eager load them
38
- properly.
39
- * Fix [issue 17](https://github.com/salsify/goldiloader/issues/17) - models eager loaded via an explicit
40
- call to eager_load now auto eager load nested models.
41
-
42
- ### 0.0.5
43
-
44
- * Fix ActiveRecord and ActiveSupport dependencies to work with versions greater than 4.1.0. Thanks for the pull
45
- requests [Alexey Volodkin](https://github.com/miraks) and [Philip Claren](https://github.com/DerKobe).
46
- * Workaround [issue 13](https://github.com/salsify/goldiloader/issues/13) by not auto-eager loading associations
47
- that use `unscope`. This workaround will be removed when the underlying
48
- [bug 11036](https://github.com/rails/rails/issues/11036) in the Rails eager loader is fixed.
49
- * Workaround [issue 11](https://github.com/salsify/goldiloader/issues/11) by not auto-eager loading associations
50
- that use `joins`. This workaround will be removed when the underlying
51
- [bug 11518](https://github.com/rails/rails/pull/11518) in the Rails eager loader is fixed.
52
- * Fix [issue 15](https://github.com/salsify/goldiloader/issues/15) - Don't auto eager load associations
53
- with finder_sql in Rails 4.0. Previously this was only done for Rails 3.2.
54
-
55
- ### 0.0.4
56
-
57
- * Fix [issue 3](https://github.com/salsify/goldiloader/issues/3) - `exists?` method should take an argument.
58
- Thanks for reporting [Bert Goethals](https://github.com/Bertg)
59
- * Fix [issue 4](https://github.com/salsify/goldiloader/issues/4) - Associations couldn't be loaded in after
60
- destroy callbacks. Thanks for reporting [Bert Goethals](https://github.com/Bertg)
61
- * Fix [issue 6](https://github.com/salsify/goldiloader/issues/6) - Models in read only associations weren't
62
- being marked as read only
63
- * Fix [issue 7](https://github.com/salsify/goldiloader/issues/7) - Don't attempt to eager load associations that
64
- aren't eager loadable e.g. if they have a limit
65
- * Fix [issue 8](https://github.com/salsify/goldiloader/issues/8) - Handle eager loading associations whose
66
- accessor methods have been overridden.
67
-
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/README.md DELETED
@@ -1,186 +0,0 @@
1
- # Goldiloader
2
-
3
- [![Gem Version](https://badge.fury.io/rb/goldiloader.png)][gem]
4
- [![Build Status](https://secure.travis-ci.org/salsify/goldiloader.png?branch=master)][travis]
5
- [![Code Climate](https://codeclimate.com/github/salsify/goldiloader.png)][codeclimate]
6
- [![Coverage Status](https://coveralls.io/repos/salsify/goldiloader/badge.png)][coveralls]
7
-
8
- [gem]: https://rubygems.org/gems/goldiloader
9
- [travis]: http://travis-ci.org/salsify/goldiloader
10
- [codeclimate]: https://codeclimate.com/github/salsify/goldiloader
11
- [coveralls]: https://coveralls.io/r/salsify/goldiloader
12
-
13
- Wouldn't it be awesome if ActiveRecord didn't make you think about eager loading and it just did the "right" thing by default? With Goldiloader it can!
14
-
15
- Consider the following models:
16
-
17
- ```ruby
18
- class Blog < ActiveRecord::Base
19
- has_many :posts
20
- end
21
-
22
- class Post < ActiveRecord::Base
23
- belongs_to :blog
24
- end
25
- ```
26
-
27
- Here are some sample queries without the Goldiloader:
28
-
29
- ```ruby
30
- > blogs = Blogs.limit(5).to_a
31
- # SELECT * FROM blogs LIMIT 5
32
-
33
- > blogs.each { |blog| blog.posts.to_a }
34
- # SELECT * FROM posts WHERE blog_id = 1
35
- # SELECT * FROM posts WHERE blog_id = 2
36
- # SELECT * FROM posts WHERE blog_id = 3
37
- # SELECT * FROM posts WHERE blog_id = 4
38
- # SELECT * FROM posts WHERE blog_id = 5
39
- ```
40
-
41
- Here are the same queries with the Goldiloader:
42
-
43
- ```ruby
44
- > blogs = Blogs.limit(5).to_a
45
- # SELECT * FROM blogs LIMIT 5
46
-
47
- > blogs.each { |blog| blog.posts.to_a }
48
- # SELECT * FROM posts WHERE blog_id IN (1,2,3,4,5)
49
- ```
50
-
51
- Whoa! It automatically loaded all of the posts for our five blogs in a single database query without specifying any eager loads! Goldiloader assumes that you'll access all models loaded from a query in a uniform way. The first time you traverse an association on any of the models it will eager load the association for all the models. It even works with arbitrary nesting of associations.
52
-
53
- Read more about the motivation for the Goldiloader in this [blog post](http://www.salsify.com/blog/automatic-eager-loading-rails/).
54
-
55
- ## Installation
56
-
57
- Add this line to your application's Gemfile:
58
-
59
- gem 'goldiloader'
60
-
61
- And then execute:
62
-
63
- $ bundle
64
-
65
- Or install it yourself as:
66
-
67
- $ gem install goldiloader
68
-
69
- ## Usage
70
-
71
- By default all associations will be automatically eager loaded when they are first accessed so hopefully most use cases should require no additional configuration. Note you're still free to explicitly eager load associations via `eager_load`, `includes`, or `preload`.
72
-
73
- ### Association Options
74
-
75
- Goldiloader supports a few options on ActiveRecord associations to customize its behavior.
76
-
77
- #### auto_include
78
-
79
- You can disable automatic eager loading on specific associations with the `auto_include` option:
80
-
81
- ```ruby
82
- class Blog < ActiveRecord::Base
83
- has_many :posts, auto_include: false
84
- end
85
- ```
86
-
87
- #### fully_load
88
-
89
- There are several association methods that ActiveRecord can either execute on in memory models or push down into SQL depending on whether or not the association is loaded. This includes the following methods:
90
-
91
- * `first`
92
- * `second`
93
- * `third`
94
- * `fourth`
95
- * `fifth`
96
- * `forty_two` (one of the hidden gems in Rails 4.1)
97
- * `last`
98
- * `size`
99
- * `ids_reader`
100
- * `empty?`
101
- * `exists?`
102
-
103
- This can cause problems for certain usage patterns if we're no longer specifying eager loads:
104
-
105
- ```ruby
106
- > blogs = Blogs.limit(5).to_a
107
- # SELECT * FROM blogs LIMIT 5
108
-
109
- > blogs.each do |blog|
110
- if blog.posts.exists?
111
- puts blog.posts
112
- else
113
- puts 'No posts'
114
- end
115
- # SELECT 1 AS one FROM posts WHERE blog_id = 1 LIMIT 1
116
- # SELECT * FROM posts WHERE blog_id IN (1,2,3,4,5)
117
- ```
118
-
119
- Notice the first call to `blog.posts.exists?` was executed via SQL because the `posts` association wasn't yet loaded. The `fully_load` option can be used to force ActiveRecord to fully load the association (and do any necessary automatic eager loading) when evaluating methods like `exists?`:
120
-
121
- ```ruby
122
- class Blog < ActiveRecord::Base
123
- has_many :posts, fully_load: true
124
- end
125
- ```
126
-
127
- ## Limitations
128
-
129
- Goldiloader leverages the ActiveRecord eager loader so it shares some of the same limitations.
130
-
131
- ### has_one associations that rely on a SQL limit
132
-
133
- You should not try to auto eager load (or regular eager load) `has_one` associations that actually correspond to multiple records and rely on a SQL limit to only return one record. Consider the following example:
134
-
135
- ```ruby
136
- class Blog < ActiveRecord::Base
137
- has_many :posts
138
- has_one :most_recent_post, -> { order(published_at: desc) }, class_name: 'Post'
139
- end
140
- ```
141
-
142
- With standard Rails lazy loading the `most_recent_post` association is loaded with a query like this:
143
-
144
- ```sql
145
- SELECT * FROM posts WHERE blog_id = 1 ORDER BY published_at DESC LIMIT 1
146
- ```
147
-
148
- With auto eager loading (or regular eager loading) the `most_recent_post` association is loaded with a query like this:
149
-
150
- ```sql
151
- SELECT * FROM posts WHERE blog_id IN (1,2,3,4,5) ORDER BY published_at DESC
152
- ```
153
-
154
- Notice the SQL limit can no longer be used which results in fetching all posts for each blog. This can cause severe performance problems if there are a large number of posts.
155
-
156
- ### Other Limitations
157
-
158
- Associations with any of the following options cannot be eager loaded:
159
-
160
- * `limit`
161
- * `offset`
162
- * `finder_sql`
163
- * `group` (due to a Rails bug)
164
- * `from` (due to a Rails bug)
165
- * `joins` (only Rails 4.0/4.1 - due to a Rails bug)
166
- * `uniq` (only Rails 3.2 - due to a Rails bug)
167
-
168
- Goldiloader detects associations with any of these options and disables automatic eager loading on them.
169
-
170
- ## Status
171
-
172
- This gem is tested with Rails 3.2, 4.0, 4.1, 4.2, and 5.0 using MRI 1.9.3, 2.0, 2.1, 2.2, 2.3, JRuby 1.7 in 1.9 mode, and JRuby 9000.
173
-
174
- Let us know if you find any issues or have any other feedback.
175
-
176
- ## Change log
177
-
178
- See the [change log](https://github.com/salsify/goldiloader/blob/master/CHANGELOG.md).
179
-
180
- ## Contributing
181
-
182
- 1. Fork it
183
- 2. Create your feature branch (`git checkout -b my-new-feature`)
184
- 3. Commit your changes (`git commit -am 'Add some feature'`)
185
- 4. Push to the branch (`git push origin my-new-feature`)
186
- 5. Create new Pull Request
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require 'bundler/setup'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec) do |task|
6
- task.verbose = false
7
- end
8
-
9
- task default: :spec
data/goldiloader.gemspec DELETED
@@ -1,40 +0,0 @@
1
- # encoding: UTF-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'goldiloader/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'goldiloader'
8
- spec.version = Goldiloader::VERSION
9
- spec.authors = ['Joel Turkel']
10
- spec.email = ['jturkel@salsify.com']
11
- spec.description = %q{Automatically eager loads Rails associations as associations are traversed}
12
- spec.summary = %q{Automatic Rails association eager loading}
13
- spec.homepage = 'https://github.com/salsify/goldiloader'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.test_files = Dir.glob('spec/**/*')
18
- spec.require_paths = ['lib']
19
-
20
- spec.add_dependency 'activerecord', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 5.1'])
21
- spec.add_dependency 'activesupport', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 5.1'])
22
-
23
- spec.add_development_dependency 'coveralls'
24
- spec.add_development_dependency 'database_cleaner', '>= 1.2'
25
- spec.add_development_dependency 'rake'
26
- spec.add_development_dependency 'rspec', '~> 3'
27
- spec.add_development_dependency 'simplecov', '~> 0.7.1'
28
- # mime-type 3 requires Ruby >= 2.0
29
- spec.add_development_dependency 'mime-types', '~> 2'
30
-
31
- if RUBY_PLATFORM == 'java'
32
- # jdbc-sqlite3 > 3.8 doesn't work with JRuby 1.7
33
- spec.add_development_dependency 'jdbc-sqlite3', '~> 3.8.11'
34
- spec.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
35
- else
36
- spec.add_development_dependency 'sqlite3'
37
- end
38
-
39
- end
40
-