Skip to content

Commit 260c207

Browse files
committed
DEV: follow rubocop rules
auto corrects existing rubocop rules so syntax is consistent
1 parent c55f060 commit 260c207

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+286
-311
lines changed

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ ruby '>= 2.2.0'
33

44
gemspec
55

6-
gem 'codecov', :require => false, :group => :test
6+
gem 'codecov', require: false, group: :test
77

88
if RUBY_VERSION < '2.2.2'
99
gem 'rack', '1.6.4'
1010
end
1111

1212
group :development do
13-
gem 'guard', :platforms => [:mri_22, :mri_23]
14-
gem 'guard-rspec', :platforms => [:mri_22, :mri_23]
13+
gem 'guard', platforms: [:mri_22, :mri_23]
14+
gem 'guard-rspec', platforms: [:mri_22, :mri_23]
1515
end

Guardfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# More info at https://github.com/guard/guard#readme
33

44
directories %w(lib spec) \
5-
.select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
5+
.select { |d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist") }
66

77
## Note: if you are using the `directories` clause above and you are not
88
## watching the project directory ('.'), then you will want to move
@@ -27,4 +27,3 @@ guard :rspec, cmd: 'bundle exec rspec', failed_mode: :focus do
2727
watch(%r{^lib/mini_profiler/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
2828
watch('spec/spec_helper.rb') { "spec" }
2929
end
30-

Rakefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require 'rubocop/rake_task'
99

1010
RuboCop::RakeTask.new
1111

12-
task :default => [:rubocop, :spec]
12+
task default: [:rubocop, :spec]
1313

1414
require 'rspec/core'
1515
require 'rspec/core/rake_task'
@@ -18,23 +18,23 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
1818
end
1919

2020
desc "builds a gem"
21-
task :build => :update_asset_version do
21+
task build: :update_asset_version do
2222
`gem build rack-mini-profiler.gemspec 1>&2`
2323
end
2424

2525
desc "compile sass"
26-
task :compile_sass => :copy_files do
26+
task compile_sass: :copy_files do
2727
`sass lib/html/includes.scss > lib/html/includes.css`
2828
end
2929

3030
desc "update asset version file"
31-
task :update_asset_version => :compile_sass do
31+
task update_asset_version: :compile_sass do
3232
require 'digest/md5'
3333
h = []
3434
Dir.glob('lib/html/*.{js,html,css,tmpl}').each do |f|
3535
h << Digest::MD5.hexdigest(::File.read(f))
3636
end
37-
File.open('lib/mini_profiler/asset_version.rb','w') do |f|
37+
File.open('lib/mini_profiler/asset_version.rb', 'w') do |f|
3838
f.write \
3939
"module Rack
4040
class MiniProfiler
@@ -44,9 +44,7 @@ end"
4444
end
4545
end
4646

47-
4847
desc "copy files from other parts of the tree"
4948
task :copy_files do
5049
# TODO grab files from MiniProfiler/UI
5150
end
52-

lib/mini_profiler/asset_version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module Rack
22
class MiniProfiler
33
ASSET_VERSION = '251162ee7dc30da30d5370581c664510'.freeze
44
end
5-
end
5+
end

lib/mini_profiler/config.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def self.default
1919
@base_url_path = "/mini-profiler-resources/".dup
2020
@disable_caching = true
2121
# called prior to rack chain, to ensure we are allowed to profile
22-
@pre_authorize_cb = lambda {|env| true}
22+
@pre_authorize_cb = lambda { |env| true }
2323

2424
# called after rack chain, to ensure we are REALLY allowed to profile
2525
@skip_schema_queries = false
2626
@storage = MiniProfiler::MemoryStore
27-
@user_provider = Proc.new{|env| Rack::Request.new(env).ip}
27+
@user_provider = Proc.new { |env| Rack::Request.new(env).ip }
2828
@authorization_mode = :allow_all
2929
@backtrace_threshold_ms = 0
3030
@flamegraph_sample_rate = 0.5
@@ -79,13 +79,12 @@ def horizontal_position
7979
position.include?('right') ? 'right' : 'left'
8080
end
8181

82-
8382
def merge!(config)
8483
if config
8584
if Hash === config
86-
config.each{|k,v| instance_variable_set "@#{k}",v}
85+
config.each { |k, v| instance_variable_set "@#{k}", v }
8786
else
88-
self.class.attributes.each{ |k|
87+
self.class.attributes.each { |k|
8988
v = config.send k
9089
instance_variable_set "@#{k}", v if v
9190
}

lib/mini_profiler/context.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
22

33
class Rack::MiniProfiler::Context
4-
attr_accessor :inject_js,:current_timer,:page_struct,:skip_backtrace,
5-
:full_backtrace,:discard, :mpt_init, :measure
4+
attr_accessor :inject_js, :current_timer, :page_struct, :skip_backtrace,
5+
:full_backtrace, :discard, :mpt_init, :measure
66

77
def initialize(opts = {})
88
opts["measure"] = true unless opts.key? "measure"
9-
opts.each do |k,v|
9+
opts.each do |k, v|
1010
self.instance_variable_set('@' + k, v)
1111
end
1212
end

lib/mini_profiler/gc_profiler.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ def object_space_stats
3030
end
3131
end
3232

33-
result = {:stats => stats, :ids => ids}
33+
result = { stats: stats, ids: ids }
3434
@ignore << result.__id__
3535

3636
result
3737
end
3838

3939
def diff_object_stats(before, after)
4040
diff = {}.compare_by_identity
41-
after.each do |k,v|
41+
after.each do |k, v|
4242
diff[k] = v - before[k]
4343
end
44-
before.each do |k,v|
44+
before.each do |k, v|
4545
diff[k] = 0 - v unless after.has_key?(k)
4646
end
4747

@@ -50,7 +50,7 @@ def diff_object_stats(before, after)
5050

5151
def analyze_strings(ids_before, ids_after)
5252
result = {}
53-
ids_after.each do |id,_|
53+
ids_after.each do |id, _|
5454
obj = ObjectSpace._id2ref(id)
5555
if String === obj && !ids_before.include?(obj.object_id)
5656
result[obj] ||= 0
@@ -64,8 +64,8 @@ def analyze_growth(ids_before, ids_after)
6464
new_objects = 0
6565
memory_allocated = 0
6666

67-
ids_after.each do |id,_|
68-
if !ids_before.include?(id) && obj=ObjectSpace._id2ref(id)
67+
ids_after.each do |id, _|
68+
if !ids_before.include?(id) && obj = ObjectSpace._id2ref(id)
6969
# this is going to be version specific (may change in 2.1)
7070
size = ObjectSpace.memsize_of(obj)
7171
memory_allocated += size
@@ -80,15 +80,15 @@ def analyze_initial_state(ids_before)
8080
memory_allocated = 0
8181
objects = 0
8282

83-
ids_before.each do |id,_|
84-
if obj=ObjectSpace._id2ref(id)
83+
ids_before.each do |id, _|
84+
if obj = ObjectSpace._id2ref(id)
8585
# this is going to be version specific (may change in 2.1)
8686
memory_allocated += ObjectSpace.memsize_of(obj)
8787
objects += 1
8888
end
8989
end
9090

91-
[objects,memory_allocated]
91+
[objects, memory_allocated]
9292
end
9393

9494
def profile_gc(app, env)
@@ -107,7 +107,7 @@ def profile_gc(app, env)
107107
# so we don't blow out on memory
108108
prev_gc_state ? GC.disable : GC.enable
109109

110-
diff = diff_object_stats(stat_before[:stats],stat_after[:stats])
110+
diff = diff_object_stats(stat_before[:stats], stat_after[:stats])
111111
string_analysis = analyze_strings(stat_before[:ids], stat_after[:ids])
112112
new_objects, memory_allocated = analyze_growth(stat_before[:ids], stat_after[:ids])
113113
objects_before, memory_before = analyze_initial_state(stat_before[:ids])
@@ -122,7 +122,7 @@ def profile_gc(app, env)
122122
123123
GC Stats:
124124
--------
125-
#{stat.map{|k,v| "#{k} : #{v}" }.sort!.join("\n")}
125+
#{stat.map { |k, v| "#{k} : #{v}" }.sort!.join("\n")}
126126
127127
New bytes allocated outside of Ruby heaps: #{memory_allocated}
128128
New objects: #{new_objects}
@@ -131,28 +131,27 @@ def profile_gc(app, env)
131131
body << "
132132
ObjectSpace delta caused by request:
133133
-----------------------------------\n"
134-
diff.to_a.delete_if{|_k, v| v == 0}.sort_by! { |_k, v| v }.reverse_each do |k,v|
134+
diff.to_a.delete_if { |_k, v| v == 0 }.sort_by! { |_k, v| v }.reverse_each do |k, v|
135135
body << "#{k} : #{v}\n"
136136
end
137137

138138
body << "\n
139139
ObjectSpace stats:
140140
-----------------\n"
141141

142-
stat_after[:stats].to_a.sort_by!{ |_k, v| v }.reverse_each do |k,v|
142+
stat_after[:stats].to_a.sort_by! { |_k, v| v }.reverse_each do |k, v|
143143
body << "#{k} : #{v}\n"
144144
end
145145

146-
147146
body << "\n
148147
String stats:
149148
------------\n"
150149

151-
string_analysis.to_a.sort_by!{ |_k, v| -v }.take(1000).each do |string,count|
150+
string_analysis.to_a.sort_by! { |_k, v| -v }.take(1000).each do |string, count|
152151
body << "#{count} : #{string}\n"
153152
end
154153

155-
return [200, {'Content-Type' => 'text/plain'}, body]
154+
return [200, { 'Content-Type' => 'text/plain' }, body]
156155
ensure
157156
prev_gc_state ? GC.disable : GC.enable
158157
end

0 commit comments

Comments
 (0)