Skip to content

Commit ac81a7c

Browse files
committed
Style/HashSyntax
1 parent 03b2587 commit ac81a7c

17 files changed

+136
-143
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ Style/GlobalVars:
7272
Exclude:
7373
- 'ext/mysql2/extconf.rb'
7474

75-
# Offense count: 175
76-
# Cop supports --auto-correct.
77-
# Configuration parameters: SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
78-
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
79-
Style/HashSyntax:
80-
EnforcedStyle: hash_rockets
81-
8275
# Offense count: 1
8376
Style/IfInsideElse:
8477
Exclude:

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ load 'tasks/benchmarks.rake'
1212
begin
1313
require 'rubocop/rake_task'
1414
RuboCop::RakeTask.new
15-
task :default => [:spec, :rubocop]
15+
task default: [:spec, :rubocop]
1616
rescue LoadError
1717
warn 'RuboCop is not available'
18-
task :default => :spec
18+
task default: :spec
1919
end

benchmark/active_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ActiveRecord::Base.default_timezone = :local
1010
ActiveRecord::Base.time_zone_aware_attributes = true
1111

12-
opts = { :database => 'test' }
12+
opts = { database: 'test' }
1313

1414
class TestModel < ActiveRecord::Base
1515
self.table_name = 'mysql2_test'
@@ -19,7 +19,7 @@ class TestModel < ActiveRecord::Base
1919

2020
Benchmark.ips do |x|
2121
%w(mysql mysql2).each do |adapter|
22-
TestModel.establish_connection(opts.merge(:adapter => adapter))
22+
TestModel.establish_connection(opts.merge(adapter: adapter))
2323

2424
x.report(adapter) do
2525
TestModel.limit(batch_size).to_a.each do |r|

benchmark/active_record_threaded.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
require 'active_record'
88

99
number_of_threads = 25
10-
opts = { :database => 'test', :pool => number_of_threads }
10+
opts = { database: 'test', pool: number_of_threads }
1111

1212
Benchmark.ips do |x|
1313
%w(mysql mysql2).each do |adapter|
14-
ActiveRecord::Base.establish_connection(opts.merge(:adapter => adapter))
14+
ActiveRecord::Base.establish_connection(opts.merge(adapter: adapter))
1515

1616
x.report(adapter) do
1717
Array.new(number_of_threads) do

benchmark/allocations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TestModel < ActiveRecord::Base
1414

1515
def bench_allocations(feature, iterations = 10, batch_size = 1000)
1616
puts "GC overhead for #{feature}"
17-
TestModel.establish_connection(:adapter => 'mysql2', :database => 'test')
17+
TestModel.establish_connection(adapter: 'mysql2', database: 'test')
1818
GC::Profiler.clear
1919
GC::Profiler.enable
2020
iterations.times { yield batch_size }

benchmark/escape.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def run_escape_benchmarks(str)
1616
mysql.quote str
1717
end
1818

19-
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
19+
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
2020
x.report "Mysql2 #{str.inspect}" do
2121
mysql2.escape str
2222
end

benchmark/query_with_mysql_casting.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def mysql_cast(type, value)
4242
debug = ENV['DEBUG']
4343

4444
Benchmark.ips do |x|
45-
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
45+
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
4646
mysql2.query "USE #{database}"
4747
x.report "Mysql2" do
48-
mysql2_result = mysql2.query sql, :symbolize_keys => true
48+
mysql2_result = mysql2.query sql, symbolize_keys: true
4949
mysql2_result.each { |res| puts res.inspect if debug }
5050
end
5151

benchmark/query_without_mysql_casting.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
debug = ENV['DEBUG']
1515

1616
Benchmark.ips do |x|
17-
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
17+
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
1818
mysql2.query "USE #{database}"
1919
x.report "Mysql2 (cast: true)" do
20-
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => true
20+
mysql2_result = mysql2.query sql, symbolize_keys: true, cast: true
2121
mysql2_result.each { |res| puts res.inspect if debug }
2222
end
2323

2424
x.report "Mysql2 (cast: false)" do
25-
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => false
25+
mysql2_result = mysql2.query sql, symbolize_keys: true, cast: false
2626
mysql2_result.each { |res| puts res.inspect if debug }
2727
end
2828

benchmark/setup_db.rb

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
]
5151

5252
# connect to localhost by default, pass options as needed
53-
@client = Mysql2::Client.new :host => "localhost", :username => "root", :database => "test"
53+
@client = Mysql2::Client.new host: "localhost", username: "root", database: "test"
5454

5555
@client.query create_table_sql
5656
@client.query 'TRUNCATE mysql2_test'
@@ -81,36 +81,36 @@ def insert_record(args)
8181
five_words = Faker::Lorem.words(rand(5))
8282
twenty5_paragraphs = Faker::Lorem.paragraphs(rand(25))
8383
insert_record(
84-
:bit_test => 1,
85-
:tiny_int_test => rand(128),
86-
:small_int_test => rand(32767),
87-
:medium_int_test => rand(8388607),
88-
:int_test => rand(2147483647),
89-
:big_int_test => rand(9223372036854775807),
90-
:float_test => rand(32767) / 1.87,
91-
:float_zero_test => 0.0,
92-
:double_test => rand(8388607) / 1.87,
93-
:decimal_test => rand(8388607) / 1.87,
94-
:decimal_zero_test => 0,
95-
:date_test => '2010-4-4',
96-
:date_time_test => '2010-4-4 11:44:00',
97-
:timestamp_test => '2010-4-4 11:44:00',
98-
:time_test => '11:44:00',
99-
:year_test => Time.now.year,
100-
:char_test => five_words.join.slice(0, 10), # CHAR(10)
101-
:varchar_test => five_words.join.slice(0, 10), # VARCHAR(10)
102-
:binary_test => five_words.join.byteslice(0, 10), # BINARY(10)
103-
:varbinary_test => five_words.join.byteslice(0, 10), # VARBINARY(10)
104-
:tiny_blob_test => five_words.join.byteslice(0, 255), # TINYBLOB
105-
:tiny_text_test => Faker::Lorem.paragraph(rand(5)).byteslice(0, 255), # TINYTEXT
106-
:blob_test => twenty5_paragraphs,
107-
:text_test => twenty5_paragraphs,
108-
:medium_blob_test => twenty5_paragraphs,
109-
:medium_text_test => twenty5_paragraphs,
110-
:long_blob_test => twenty5_paragraphs,
111-
:long_text_test => twenty5_paragraphs,
112-
:enum_test => %w(val1 val2).sample,
113-
:set_test => %w(val1 val2 val1,val2).sample,
84+
bit_test: 1,
85+
tiny_int_test: rand(128),
86+
small_int_test: rand(32767),
87+
medium_int_test: rand(8388607),
88+
int_test: rand(2147483647),
89+
big_int_test: rand(9223372036854775807),
90+
float_test: rand(32767) / 1.87,
91+
float_zero_test: 0.0,
92+
double_test: rand(8388607) / 1.87,
93+
decimal_test: rand(8388607) / 1.87,
94+
decimal_zero_test: 0,
95+
date_test: '2010-4-4',
96+
date_time_test: '2010-4-4 11:44:00',
97+
timestamp_test: '2010-4-4 11:44:00',
98+
time_test: '11:44:00',
99+
year_test: Time.now.year,
100+
char_test: five_words.join.slice(0, 10), # CHAR(10)
101+
varchar_test: five_words.join.slice(0, 10), # VARCHAR(10)
102+
binary_test: five_words.join.byteslice(0, 10), # BINARY(10)
103+
varbinary_test: five_words.join.byteslice(0, 10), # VARBINARY(10)
104+
tiny_blob_test: five_words.join.byteslice(0, 255), # TINYBLOB
105+
tiny_text_test: Faker::Lorem.paragraph(rand(5)).byteslice(0, 255), # TINYTEXT
106+
blob_test: twenty5_paragraphs,
107+
text_test: twenty5_paragraphs,
108+
medium_blob_test: twenty5_paragraphs,
109+
medium_text_test: twenty5_paragraphs,
110+
long_blob_test: twenty5_paragraphs,
111+
long_text_test: twenty5_paragraphs,
112+
enum_test: %w(val1 val2).sample,
113+
set_test: %w(val1 val2 val1,val2).sample,
114114
)
115115
if n % 100 == 0
116116
$stdout.putc '.'

examples/threaded.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
overhead = rand(3)
1212
puts ">> thread #{Thread.current.object_id} query, #{overhead} sec overhead"
1313
# 3 second overhead per query
14-
Mysql2::Client.new(:host => "localhost", :username => "root").query("SELECT sleep(#{overhead}) as result")
14+
Mysql2::Client.new(host: "localhost", username: "root").query("SELECT sleep(#{overhead}) as result")
1515
puts "<< thread #{Thread.current.object_id} result, #{overhead} sec overhead"
1616
end
1717
end.each(&:join)

0 commit comments

Comments
 (0)