Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby Warnings #331

Merged
merged 8 commits into from
Feb 3, 2018
2 changes: 2 additions & 0 deletions lib/mini_profiler/client_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def initialize(env, store, start)
@cookie = request.cookies[COOKIE_NAME]
@store = store
@start = start
@backtrace_level = nil
@orig_disable_profiling = @disable_profiling = nil

@allowed_tokens, @orig_auth_tokens = nil

Expand Down
17 changes: 9 additions & 8 deletions lib/mini_profiler/profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ def serve_results(env)
end

def generate_html(page_struct, env, result_json = page_struct.to_json)
path = "#{env['RACK_MINI_PROFILER_ORIGINAL_SCRIPT_NAME']}#{@config.base_url_path}"
version = MiniProfiler::ASSET_VERSION
json = result_json
includes = get_profile_script(env)
name = page_struct[:name]
duration = page_struct.duration_ms.round(1).to_s
# double-assigning to suppress "assigned but unused variable" warnings
path = path = "#{env['RACK_MINI_PROFILER_ORIGINAL_SCRIPT_NAME']}#{@config.base_url_path}"
version = version = MiniProfiler::ASSET_VERSION
json = json = result_json
includes = includes = get_profile_script(env)
name = name = page_struct[:name]
duration = duration = page_struct.duration_ms.round(1).to_s

MiniProfiler.share_template.result(binding)
end
Expand Down Expand Up @@ -413,8 +414,8 @@ def dump_exceptions(exceptions)
body << "No exceptions raised"
else
body << "Exceptions: (#{exceptions.size} total)\n"
exceptions.group_by(&:class).each do |klass, exceptions|
body << " #{klass.name} (#{exceptions.size})\n"
exceptions.group_by(&:class).each do |klass, exceptions_per_class|
body << " #{klass.name} (#{exceptions_per_class.size})\n"
end

body << "\nBacktraces\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/mini_profiler/storage/file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def [](key)
begin
data = ::File.open(path(key),"rb") {|f| f.read}
return Marshal.load data
rescue => e
rescue
return nil
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mini_profiler/storage/memory_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def initialize(args = nil)
args ||= {}
@expires_in_seconds = args.fetch(:expires_in) { EXPIRES_IN_SECONDS }

@token1, @token2, @cycle_tokens_at = nil
@token1, @token2, @cycle_at = nil

initialize_locks
initialize_cleanup_thread(args)
Expand All @@ -70,7 +70,7 @@ def initialize_locks
def initialize_cleanup_thread(args={})
cleanup_interval = args.fetch(:cleanup_interval) { CLEANUP_INTERVAL }
cleanup_cycle = args.fetch(:cleanup_cycle) { CLEANUP_CYCLE }
t = CacheCleanupThread.new(cleanup_interval, cleanup_cycle, self) do |t|
t = CacheCleanupThread.new(cleanup_interval, cleanup_cycle, self) do
until Thread.current[:should_exit] do
CacheCleanupThread.current.sleepy_run
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mini_profiler_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Rack::MiniProfilerRails
# call direct if needed to do a defer init
def self.initialize!(app)

raise "MiniProfilerRails initialized twice. Set `require: false' for rack-mini-profiler in your Gemfile" if @already_initialized
raise "MiniProfilerRails initialized twice. Set `require: false' for rack-mini-profiler in your Gemfile" if defined?(@already_initialized) && @already_initialized

c = Rack::MiniProfiler.config

Expand Down
12 changes: 6 additions & 6 deletions spec/lib/timer_struct/sql_timer_struct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@

it 'includes rspec in the trace (default is no filter)' do
sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil)
expect(sql[:stack_trace_snippet]).to match /rspec/
expect(sql[:stack_trace_snippet]).to match(/rspec/)
end

it "doesn't include rspec if we filter for only app" do
Rack::MiniProfiler.config.backtrace_includes = [/\/app/]
sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil)
expect(sql[:stack_trace_snippet]).not_to match /rspec/
expect(sql[:stack_trace_snippet]).not_to match(/rspec/)
end

it "includes rspec if we filter for it" do
Rack::MiniProfiler.config.backtrace_includes = [/\/(app|rspec)/]
sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil)
expect(sql[:stack_trace_snippet]).to match /rspec/
expect(sql[:stack_trace_snippet]).to match(/rspec/)
end

it "includes rspec if we filter for it along with something else" do
Rack::MiniProfiler.config.backtrace_includes = [/rspec/, /something_else/]
sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil)
expect(sql[:stack_trace_snippet]).to match /rspec/
expect(sql[:stack_trace_snippet]).to match(/rspec/)
end

it "ignores rspec if we specifically ignore it" do
Rack::MiniProfiler.config.backtrace_ignores = [/\/rspec/]
sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil)
expect(sql[:stack_trace_snippet]).not_to match /rspec/
expect(sql[:stack_trace_snippet]).not_to match(/rspec/)
end

it "ignores rspec if we specifically ignore it along with something else" do
Rack::MiniProfiler.config.backtrace_ignores = [/\/rspec/, /something_else/]
sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil)
expect(sql[:stack_trace_snippet]).not_to match /rspec/
expect(sql[:stack_trace_snippet]).not_to match(/rspec/)
end

it "should omit the backtrace if the query takes less than the threshold time" do
Expand Down