Skip to content

Commit cc8e3d9

Browse files
committed
ruby 3
1 parent 3abbb49 commit cc8e3d9

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ inherit_gem:
22
rubocop-rails_config:
33
- config/rails.yml
44

5+
AllCops:
6+
TargetRubyVersion: 3.1
7+
58
Style/ClassAndModuleChildren:
69
EnforcedStyle: nested
710

jit_preloader.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Gem::Specification.new do |spec|
1515
spec.homepage = 'https://github.com/clio/jit_preloader'
1616
spec.metadata['homepage_uri'] = spec.homepage
1717
spec.metadata['source_code_uri'] = spec.homepage
18+
spec.required_ruby_version = '>= 3.0.0'
1819

19-
spec.license = 'MIT'
20+
spec.license = 'MIT'
2021

2122
spec.files = Dir.glob('lib/**/*.rb') + [File.basename(__FILE__)]
2223
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }

lib/jit_preloader/active_record/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def preload_scoped_relation(name:, base_association:, preload_scope: nil)
3636
end
3737

3838
preloader_association = ActiveRecord::Associations::Preloader.new(
39-
records: records,
39+
records:,
4040
associations: base_association,
4141
scope: preload_scope
4242
).call.first

lib/jit_preloader/preloader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def jit_preload(associations)
2121
# Some of the records may already have the association loaded and we should not load them again
2222
records_requiring_loading = records_with_association.select { |r| !r.association(associations).loaded? }
2323

24-
self.class.new(records: records_requiring_loading, associations: associations).call
24+
self.class.new(records: records_requiring_loading, associations:).call
2525
end
2626
else
2727
def self.attach(records)

spec/lib/jit_preloader/preloader_spec.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
PhoneNumber.new(phone: '4445556666'),
1515
PhoneNumber.new(phone: '2223333444')
1616
]
17-
Contact.create(name: 'Only Addresses', addresses: addresses, phone_numbers: phones)
17+
Contact.create(name: 'Only Addresses', addresses:, phone_numbers: phones)
1818
end
1919

2020
let!(:contact2) do
@@ -28,7 +28,7 @@
2828
]
2929
Contact.create(
3030
name: 'Both!',
31-
addresses: addresses,
31+
addresses:,
3232
email_address: EmailAddress.new(address: '[email protected]'),
3333
phone_numbers: [PhoneNumber.new(phone: '1234567890')]
3434
)
@@ -54,8 +54,8 @@
5454
context 'for single table inheritance' do
5555
context 'when preloading an aggregate for a child model' do
5656
let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') }
57-
let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) }
58-
let!(:company2) { Company.create(name: 'Company2', contact_book: contact_book) }
57+
let!(:company1) { Company.create(name: 'Company1', contact_book:) }
58+
let!(:company2) { Company.create(name: 'Company2', contact_book:) }
5959

6060
it 'can handle queries' do
6161
contact_books = ContactBook.jit_preload.to_a
@@ -65,11 +65,11 @@
6565

6666
context 'when preloading an aggregate of a child model through its base model' do
6767
let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') }
68-
let!(:contact) { Contact.create(name: 'Contact', contact_book: contact_book) }
69-
let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) }
70-
let!(:company2) { Company.create(name: 'Company2', contact_book: contact_book) }
71-
let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact: contact) }
72-
let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact: contact) }
68+
let!(:contact) { Contact.create(name: 'Contact', contact_book:) }
69+
let!(:company1) { Company.create(name: 'Company1', contact_book:) }
70+
let!(:company2) { Company.create(name: 'Company2', contact_book:) }
71+
let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact:) }
72+
let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact:) }
7373
let!(:company_employee1) { Employee.create(name: 'Company Employee1', contact: company1) }
7474
let!(:company_employee2) { Employee.create(name: 'Company Employee2', contact: company2) }
7575

@@ -81,11 +81,11 @@
8181

8282
context 'when preloading an aggregate of a nested child model through another child model' do
8383
let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') }
84-
let!(:contact) { Contact.create(name: 'Contact', contact_book: contact_book) }
85-
let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) }
86-
let!(:company2) { Company.create(name: 'Company2', contact_book: contact_book) }
87-
let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact: contact) }
88-
let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact: contact) }
84+
let!(:contact) { Contact.create(name: 'Contact', contact_book:) }
85+
let!(:company1) { Company.create(name: 'Company1', contact_book:) }
86+
let!(:company2) { Company.create(name: 'Company2', contact_book:) }
87+
let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact:) }
88+
let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact:) }
8989
let!(:company_employee1) { Employee.create(name: 'Company Employee1', contact: company1) }
9090
let!(:company_employee2) { Employee.create(name: 'Company Employee2', contact: company2) }
9191

@@ -100,8 +100,8 @@
100100
let!(:child1) { Child.create(name: 'Child1') }
101101
let!(:child2) { Child.create(name: 'Child2') }
102102
let!(:child3) { Child.create(name: 'Child3') }
103-
let!(:parent1) { Parent.create(name: 'Parent1', contact_book: contact_book, children: [child1, child2]) }
104-
let!(:parent2) { Parent.create(name: 'Parent2', contact_book: contact_book, children: [child2, child3]) }
103+
let!(:parent1) { Parent.create(name: 'Parent1', contact_book:, children: [child1, child2]) }
104+
let!(:parent2) { Parent.create(name: 'Parent2', contact_book:, children: [child2, child3]) }
105105

106106
it 'can handle queries' do
107107
contact_books = ContactBook.jit_preload.to_a
@@ -112,9 +112,9 @@
112112

113113
context 'when preloading an aggregate for a child model scoped by another join table' do
114114
let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') }
115-
let!(:contact1) { Company.create(name: 'Without Email', contact_book: contact_book) }
116-
let!(:contact2) { Company.create(name: 'With Blank Email', email_address: EmailAddress.new(address: ''), contact_book: contact_book) }
117-
let!(:contact3) { Company.create(name: 'With Email', email_address: EmailAddress.new(address: '[email protected]'), contact_book: contact_book) }
115+
let!(:contact1) { Company.create(name: 'Without Email', contact_book:) }
116+
let!(:contact2) { Company.create(name: 'With Blank Email', email_address: EmailAddress.new(address: ''), contact_book:) }
117+
let!(:contact3) { Company.create(name: 'With Email', email_address: EmailAddress.new(address: '[email protected]'), contact_book:) }
118118

119119
it 'can handle queries' do
120120
contact_books = ContactBook.jit_preload.to_a
@@ -230,8 +230,8 @@
230230

231231
context 'when accessing an association with a scope that has a parameter' do
232232
let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') }
233-
let!(:contact) { Contact.create(name: 'Contact', contact_book: contact_book) }
234-
let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) }
233+
let!(:contact) { Contact.create(name: 'Contact', contact_book:) }
234+
let!(:company1) { Company.create(name: 'Company1', contact_book:) }
235235

236236
it 'is unable to be preloaded' do
237237
ActiveSupport::Notifications.subscribed(callback, 'n_plus_one_query') do

0 commit comments

Comments
 (0)