Skip to content

Commit

Permalink
rubocop corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahramadan committed Feb 2, 2023
1 parent a49526e commit 1969abe
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion infinite_tracing/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Rake::TestTask.new do |t|
t.libs << "#{ROOT}/test"
t.libs << "#{ROOT}/lib"
t.pattern = Array(file_pattern).join(",")
t.verbose = ENV["VERBOSE"]
t.verbose = ENV.fetch("VERBOSE", nil)
end
6 changes: 3 additions & 3 deletions lib/new_relic/agent/configuration/environment_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def set_log_file
if ENV['NEW_RELIC_LOG'].casecmp(NewRelic::STANDARD_OUT) == 0
self[:log_file_path] = self[:log_file_name] = NewRelic::STANDARD_OUT
else
self[:log_file_path] = File.dirname(ENV['NEW_RELIC_LOG'])
self[:log_file_name] = File.basename(ENV['NEW_RELIC_LOG'])
self[:log_file_path] = File.dirname(ENV.fetch('NEW_RELIC_LOG', nil))
self[:log_file_name] = File.basename(ENV.fetch('NEW_RELIC_LOG', nil))
end
end
end
Expand All @@ -80,7 +80,7 @@ def set_value_from_environment_variable(key)
end

def set_key_by_type(config_key, environment_key)
value = ENV[environment_key]
value = ENV.fetch(environment_key, nil)
type = self.type_map[config_key]

if type == String
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/agent/connect/request_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sanitize_environment_report(environment_report)

def environment_metadata
env_copy = {}
ENV.keys.each { |k| env_copy[k] = ENV[k] if k =~ /^NEW_RELIC_METADATA_/ }
ENV.keys.each { |k| env_copy[k] = ENV.fetch(k, nil) if k =~ /^NEW_RELIC_METADATA_/ }
env_copy
end

Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/agent/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module NewRelic
module Agent
module Hostname
def self.get
dyno_name = ENV['DYNO']
dyno_name = ENV.fetch('DYNO', nil)
@hostname ||= if dyno_name && ::NewRelic::Agent.config[:'heroku.use_dyno_names']
matching_prefix = heroku_dyno_name_prefix(dyno_name)
dyno_name = "#{matching_prefix}.*" if matching_prefix
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/cli/commands/deployments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize(command_line_args)
@user = nil
super(command_line_args)
@description ||= @leftover && @leftover.join(" ")
@user ||= ENV['USER']
@user ||= ENV.fetch('USER', nil)
control.env = @environment if @environment

load_yaml_from_env(control.env)
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/environment_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def self.registered_reporters=(logic)
if defined? ::Rails and ::Rails.respond_to?(:env)
::Rails.env.to_s
else
ENV['RAILS_ENV']
ENV.fetch('RAILS_ENV', nil)
end
end
report_on('OpenSSL version') { ::OpenSSL::OPENSSL_VERSION }
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/local_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def check_for_delayed_job
end

def check_for_resque
has_queue = ENV['QUEUE'] || ENV['QUEUES']
has_queue = ENV['QUEUE'] || ENV.fetch('QUEUES', nil)
resque_rake = executable == 'rake' && ARGV.include?('resque:work')
resque_pool_rake = executable == 'rake' && ARGV.include?('resque:pool')
resque_pool_executable = executable == 'resque-pool' && defined?(::Resque::Pool)
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/tests.rake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if defined? Rake::TestTask
agent_home = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))

Rake::TestTask.new(:newrelic) do |t|
file_pattern = ENV["file"]
file_pattern = ENV.fetch("file", nil)
file_pattern = file_pattern.split(",").map { |f| "#{agent_home}/#{f}".gsub("//", "/") } if file_pattern
file_pattern ||= "#{agent_home}/test/new_relic/**/*_test.rb"

Expand Down
2 changes: 1 addition & 1 deletion test/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def self.safe_restore(old_env)
# runs given block, then restores ENV to original state before returning.
def self.inject(env, &block)
old_env = {}
env.each { |key, val| old_env[key] = ENV[key] }
env.each { |key, val| old_env[key] = ENV.fetch(key, nil) }
begin
safe_update(env)
yield
Expand Down
2 changes: 1 addition & 1 deletion test/environments/lib/environments/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def run_and_report
failures = []

puts yellow("Tests to run:\n\t#{tests_to_run.map { |s| s.gsub(env_root + "/", "") }.join("\n\t")}") if ENV['VERBOSE_TEST_OUTPUT']
env_file = ENV["file"]
env_file = ENV.fetch("file", nil)

tests_to_run.each do |dir|
Bundler.with_unbundled_env do
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def puke_fast(klass, meth, e)
end

def fail_fast?
ENV['MT_FAIL_FAST']
ENV.fetch('MT_FAIL_FAST', nil)
end
end)
4 changes: 2 additions & 2 deletions test/multiverse/lib/multiverse/suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def with_potentially_mismatched_bundler
puts "Encountered Bundler error: #{error.message}"
puts "Currently Active Bundler Version: #{::Bundler::VERSION}"
end
change_lock_version(`pwd`, ENV["BUNDLE_GEMFILE"])
change_lock_version(`pwd`, ENV.fetch("BUNDLE_GEMFILE", nil))
@retried = true
retry
end
Expand Down Expand Up @@ -177,7 +177,7 @@ def bundle_install(dir)
result = ShellUtils.try_command_n_times(full_bundle_cmd, 3)
unless $?.success?
puts "Failed local bundle, trying again without the version lock..."
change_lock_version(dir, ENV["BUNDLE_GEMFILE"])
change_lock_version(dir, ENV.fetch("BUNDLE_GEMFILE", nil))
result = ShellUtils.try_command_n_times(full_bundle_cmd, 3)
end

Expand Down
2 changes: 1 addition & 1 deletion test/multiverse/suites/active_record/config/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if defined?(ActiveRecord::VERSION)
ENV['DATABASE_NAME'] = "multiverse_activerecord_#{ActiveRecord::VERSION::STRING}_#{RUBY_VERSION}_#{RUBY_ENGINE}".tr(".", "_")
else
ENV['DATABASE_NAME'] = "multiverse_activerecord_2_x_#{ENV["MULTIVERSE_ENV"]}_#{RUBY_VERSION}_#{RUBY_ENGINE}".tr(".", "_")
ENV['DATABASE_NAME'] = "multiverse_activerecord_2_x_#{ENV.fetch("MULTIVERSE_ENV", nil)}_#{RUBY_VERSION}_#{RUBY_ENGINE}".tr(".", "_")
end

config_raw = File.read(File.join(config_dir, 'database.yml'))
Expand Down
2 changes: 1 addition & 1 deletion test/multiverse/suites/active_record_pg/config/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if defined?(ActiveRecord::VERSION)
ENV['DATABASE_NAME'] = "multiverse_activerecord_#{ActiveRecord::VERSION::STRING}_#{RUBY_VERSION}_#{RUBY_ENGINE}".tr(".", "_")
else
ENV['DATABASE_NAME'] = "multiverse_activerecord_2_x_#{ENV["MULTIVERSE_ENV"]}_#{RUBY_VERSION}_#{RUBY_ENGINE}".tr(".", "_")
ENV['DATABASE_NAME'] = "multiverse_activerecord_2_x_#{ENV.fetch("MULTIVERSE_ENV", nil)}_#{RUBY_VERSION}_#{RUBY_ENGINE}".tr(".", "_")
end

config_raw = File.read(File.join(config_dir, 'database.yml'))
Expand Down
2 changes: 1 addition & 1 deletion test/multiverse/suites/capistrano/config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
ENV.keys.each do |key|
if key.include?('NEWRELIC_CAPISTRANO_')
name = key.gsub('NEWRELIC_CAPISTRANO_', '').downcase
set "newrelic_#{name}".to_sym, ENV[key]
set "newrelic_#{name}".to_sym, ENV.fetch(key, nil)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def test_config_loads_from_newrelic_yml
end

def test_config_loads_from_home_newrelic_yml
assert_config_read_from(ENV['HOME'] + "/newrelic.yml")
assert_config_read_from(ENV.fetch('HOME', nil) + "/newrelic.yml")
end

def test_config_loads_from_home_dot_newrelic_newrelic_yml
assert_config_read_from(ENV['HOME'] + "/.newrelic/newrelic.yml")
assert_config_read_from(ENV.fetch('HOME', nil) + "/.newrelic/newrelic.yml")
end

def test_config_loads_from_config_path_option_to_manual_start
Expand Down
2 changes: 1 addition & 1 deletion test/new_relic/framework_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Base
end

# does the path match "rails\d" (ex: rails7) or "railsedge"?
if ENV['BUNDLE_GEMFILE'] =~ /rails(?:\d|edge)/
if ENV.fetch('BUNDLE_GEMFILE', nil) =~ /rails(?:\d|edge)/
# rubocop:disable Performance/StringInclude
assert_truthy NewRelic::Agent.config[:framework].match(/rails/)
# rubocop:enable Performance/StringInclude
Expand Down

0 comments on commit 1969abe

Please sign in to comment.