Skip to content

Commit b47af33

Browse files
authored
Some minor rubocop appeasement (#3003)
* another batch of straightforward linter appeasements * redundant relative path * copilot suggestions
1 parent 313d35e commit b47af33

15 files changed

+130
-128
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ Metrics/ModuleLength:
6363
Metrics/MethodLength:
6464
Max: 20
6565

66+
Naming/FileName:
67+
Exclude:
68+
- 'gemfiles/bson_4-stable.gemfile'
69+
6670
Naming/MethodParameterName:
6771
AllowedNames: [ id, op ]
6872

Gemfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
source 'https://rubygems.org'
54

65
gemspec
76

8-
require_relative './gemfiles/standard'
7+
require_relative 'gemfiles/standard'
98

109
standard_dependencies

Rakefile

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
require 'bundler'
54
require 'rspec/core/rake_task'
65

7-
if File.exist?('./spec/shared/lib/tasks/candidate.rake')
8-
load 'spec/shared/lib/tasks/candidate.rake'
9-
end
6+
load 'spec/shared/lib/tasks/candidate.rake' if File.exist?('./spec/shared/lib/tasks/candidate.rake')
107

118
ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
129

13-
$: << File.join(ROOT, 'spec/shared/lib')
10+
$LOAD_PATH << File.join(ROOT, 'spec/shared/lib')
1411

12+
# rubocop:disable Style/RegexpLiteral
1513
CLASSIFIERS = [
16-
[%r,^mongo/server,, :unit_server],
17-
[%r,^mongo,, :unit],
18-
[%r,^kerberos,, :unit],
19-
[%r,^integration/sdam_error_handling,, :sdam_integration],
20-
[%r,^integration/cursor_reaping,, :cursor_reaping],
21-
[%r,^integration/query_cache,, :query_cache],
22-
[%r,^integration/transactions_examples,, :tx_examples],
23-
[%r,^(atlas|integration),, :integration],
24-
[%r,^spec_tests/sdam_integration,, :spec_sdam_integration],
25-
[%r,^spec_tests,, :spec],
26-
]
14+
[ %r{^mongo/server}, :unit_server ],
15+
[ %r{^mongo}, :unit ],
16+
[ %r{^kerberos}, :unit ],
17+
[ %r{^integration/sdam_error_handling}, :sdam_integration ],
18+
[ %r{^integration/cursor_reaping}, :cursor_reaping ],
19+
[ %r{^integration/query_cache}, :query_cache ],
20+
[ %r{^integration/transactions_examples}, :tx_examples ],
21+
[ %r{^(atlas|integration)}, :integration ],
22+
[ %r{^spec_tests/sdam_integration}, :spec_sdam_integration ],
23+
[ %r{^spec_tests}, :spec ],
24+
].freeze
25+
# rubocop:enable Style/RegexpLiteral
2726

2827
RUN_PRIORITY = (ENV['RUN_PRIORITY'] || %(
2928
tx_examples
3029
unit unit_server
3130
integration sdam_integration cursor_reaping query_cache
3231
spec spec_sdam_integration
33-
)).split.map(&:to_sym)
32+
)).split.map(&:to_sym).freeze
33+
34+
def spec_organizer
35+
require 'mrss/spec_organizer'
36+
37+
Mrss::SpecOrganizer.new(
38+
root: ROOT,
39+
classifiers: CLASSIFIERS,
40+
priority_order: RUN_PRIORITY
41+
)
42+
end
3443

3544
RSpec::Core::RakeTask.new(:spec) do |t|
36-
#t.rspec_opts = "--profile 5" if ENV['CI']
45+
# t.rspec_opts = '--profile 5' if ENV['CI']
3746
end
3847

39-
task :default => ['spec:prepare', :spec]
48+
task default: [ 'spec:prepare', :spec ]
4049

4150
desc 'Build the gem'
4251
task :build do
@@ -46,12 +55,12 @@ task :build do
4655
system(*command)
4756
end
4857

49-
# `rake version` is used by the deployment system so get the release version
50-
# of the product beng deployed. It must do nothing more than just print the
58+
# `rake version` is used by the deployment system to get the release version
59+
# of the product being deployed. It must do nothing more than just print the
5160
# product version number.
52-
#
53-
# See the mongodb-labs/driver-github-tools/ruby/publish Github action.
54-
desc "Print the current value of Mongo::VERSION"
61+
#
62+
# See the mongodb-labs/driver-github-tools/ruby/publish GitHub action.
63+
desc 'Print the current value of Mongo::VERSION'
5564
task :version do
5665
require 'mongo/version'
5766

@@ -62,6 +71,7 @@ end
6271
# builds the gem. Our release process assumes the gem has already
6372
# been built (and signed via GPG), so we just need `rake release` to
6473
# push the gem to rubygems.
74+
desc 'Push the built gem to RubyGems. This should only be invoked from the Driver Release GitHub action.'
6575
task :release do
6676
require 'mongo/version'
6777

@@ -82,14 +92,16 @@ task :release do
8292
system 'gem', 'push', "mongo-#{Mongo::VERSION}.gem"
8393
end
8494

95+
desc 'Load the MongoDB Ruby driver. This is a prerequisite for many other tasks.'
8596
task :mongo do
8697
require 'mongo'
8798
end
8899

100+
# rubocop:disable Metrics/BlockLength
89101
namespace :spec do
90102
desc 'Creates necessary user accounts in the cluster'
91103
task prepare: :mongo do
92-
$: << File.join(File.dirname(__FILE__), 'spec')
104+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'spec')
93105

94106
require 'support/utils'
95107
require 'support/spec_setup'
@@ -98,7 +110,7 @@ namespace :spec do
98110

99111
desc 'Waits for sessions to be available in the deployment'
100112
task wait_for_sessions: :mongo do
101-
$: << File.join(File.dirname(__FILE__), 'spec')
113+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'spec')
102114

103115
require 'support/utils'
104116
require 'support/spec_config'
@@ -108,21 +120,20 @@ namespace :spec do
108120
client.database.command(ping: 1)
109121
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 300
110122
loop do
111-
begin
112-
client.cluster.validate_session_support!
113-
break
114-
rescue Mongo::Error::SessionsNotSupported
115-
if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
116-
raise "Sessions did not become supported in 300 seconds"
117-
end
118-
client.cluster.scan!
123+
client.cluster.validate_session_support!
124+
break
125+
rescue Mongo::Error::SessionsNotSupported
126+
if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
127+
raise 'Sessions did not become supported in 300 seconds'
119128
end
129+
130+
client.cluster.scan!
120131
end
121132
end
122133

123134
desc 'Prints configuration used by the test suite'
124135
task config: :mongo do
125-
$: << File.join(File.dirname(__FILE__), 'spec')
136+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'spec')
126137

127138
# Since this task is usually used for troubleshooting of test suite
128139
# configuration, leave driver log level at the default of debug to
@@ -133,17 +144,7 @@ namespace :spec do
133144
SpecConfig.instance.print_summary
134145
end
135146

136-
def spec_organizer
137-
require 'mrss/spec_organizer'
138-
139-
Mrss::SpecOrganizer.new(
140-
root: ROOT,
141-
classifiers: CLASSIFIERS,
142-
priority_order: RUN_PRIORITY,
143-
)
144-
end
145-
146-
task :ci => ['spec:prepare'] do
147+
task ci: [ 'spec:prepare' ] do
147148
spec_organizer.run
148149
end
149150

@@ -154,6 +155,7 @@ namespace :spec do
154155
end
155156
end
156157
end
158+
# rubocop:enable Metrics/BlockLength
157159

158160
desc 'Build and validate the evergreen config'
159161
task eg: %w[ eg:build eg:validate ]
@@ -181,11 +183,11 @@ namespace :eg do
181183
end
182184
end
183185

184-
desc "Generate all documentation"
185-
task :docs => 'docs:yard'
186+
desc 'Generate all documentation'
187+
task docs: 'docs:yard'
186188

187189
namespace :docs do
188-
desc "Generate yard documention"
190+
desc 'Generate yard documentation'
189191
task :yard do
190192
out = File.join('yard-docs', Mongo::VERSION)
191193
FileUtils.rm_rf(out)

examples/aggregate.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
# Group documents by field and calculate count.
54

65
coll = client[:restaurants]
76

87
results = coll.find.aggregate([ { '$group' => { '_id' => '$borough',
9-
'count' => { '$sum' => 1 }
10-
}
11-
}
12-
])
8+
'count' => { '$sum' => 1 } } } ])
139

1410
results.each do |result|
1511
puts result
@@ -19,9 +15,8 @@
1915

2016
results = coll.find.aggregate([ { '$match' => { 'borough' => 'Queens',
2117
'cuisine' => 'Brazilian' } },
22-
{ '$group' => { '_id' => '$address.zipcode',
23-
'count' => { '$sum' => 1 } } }
24-
])
18+
{ '$group' => { '_id' => '$address.zipcode',
19+
'count' => { '$sum' => 1 } } } ])
2520

2621
results.each do |result|
2722
puts result

examples/create.rb

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
# Insert a document
54

65
require 'date'
76

8-
result = client[:restaurants].insert_one({
9-
address: {
10-
street: '2 Avenue',
11-
zipcode: 10075,
12-
building: 1480,
13-
coord: [-73.9557413, 40.7720266]
14-
},
15-
borough: 'Manhattan',
16-
cuisine: 'Italian',
17-
grades: [
18-
{
19-
date: DateTime.strptime('2014-10-01', '%Y-%m-%d'),
20-
grade: 'A',
21-
score: 11
22-
},
23-
{
24-
date: DateTime.strptime('2014-01-16', '%Y-%m-%d'),
25-
grade: 'B',
26-
score: 17
27-
}
28-
],
29-
name: 'Vella',
30-
restaurant_id: '41704620'
31-
})
7+
result = client[:restaurants]
8+
.insert_one({ address: {
9+
street: '2 Avenue',
10+
zipcode: '10075',
11+
building: 1480,
12+
coord: [ -73.9557413, 40.7720266 ]
13+
},
14+
borough: 'Manhattan',
15+
cuisine: 'Italian',
16+
grades: [
17+
{
18+
date: DateTime.strptime('2014-10-01', '%Y-%m-%d'),
19+
grade: 'A',
20+
score: 11
21+
},
22+
{
23+
date: DateTime.strptime('2014-01-16', '%Y-%m-%d'),
24+
grade: 'B',
25+
score: 17
26+
}
27+
],
28+
name: 'Vella',
29+
restaurant_id: '41704620' })
3230

3331
result.n #=> returns 1, because 1 document was inserted.

examples/delete.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
# Delete all documents matching a condition
54

examples/index.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
# Create a single field index
54

65
result = client[:restaurants].indexes.create_one(cuisine: Mongo::Index::ASCENDING)
6+
p result.ok?
77

88
# Create a compound index
99

1010
result = client[:restaurants].indexes.create_one(cuisine: 1, zipcode: Mongo::Index::DESCENDING)
11+
p result.ok?
1112

1213
# Create a single field unique index
1314

1415
result = client[:restaurants].indexes.create_one({ cuisine: Mongo::Index::ASCENDING }, unique: true)
16+
p result.ok?

examples/query.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
# Query for all documents in a collection
54

@@ -49,21 +48,19 @@
4948
puts doc
5049
end
5150

52-
# Query with a logical conjuction (AND) of query conditions
51+
# Query with a logical conjunction (AND) of query conditions
5352

5453
cursor = client[:restaurants].find({ 'cuisine' => 'Italian',
55-
'address.zipcode' => '10075'})
54+
'address.zipcode' => '10075' })
5655

5756
cursor.each do |doc|
5857
puts doc
5958
end
6059

6160
# Query with a logical disjunction (OR) of query conditions
6261

63-
cursor = client[:restaurants].find('$or' => [{ 'cuisine' => 'Italian' },
64-
{ 'address.zipcode' => '10075'}
65-
]
66-
)
62+
cursor = client[:restaurants].find('$or' => [ { 'cuisine' => 'Italian' },
63+
{ 'address.zipcode' => '10075' } ])
6764

6865
cursor.each do |doc|
6966
puts doc

gemfiles/bson_4-stable.gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# rubocop:todo all
2-
source "https://rubygems.org"
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
34
gemspec path: '..'
45

56
gem 'bson', git: 'https://github.com/mongodb/bson-ruby', branch: '4-stable'
67

7-
require_relative './standard'
8+
require_relative 'standard'
89

910
standard_dependencies

gemfiles/bson_master.gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# rubocop:todo all
2-
source "https://rubygems.org"
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
34
gemspec path: '..'
45

56
gem 'bson', git: 'https://github.com/mongodb/bson-ruby', branch: 'master'
67

7-
require_relative './standard'
8+
require_relative 'standard'
89

910
standard_dependencies

0 commit comments

Comments
 (0)