From feec888ff8ad0510da6d9da537451df1289f38d4 Mon Sep 17 00:00:00 2001 From: Herwin Date: Tue, 2 Oct 2018 19:39:47 +0200 Subject: [PATCH] Prefer __dir__ over File.dirname(__FILE__) (#104) It is shorter and looks a whole lot cleaner --- Rakefile | 6 +++--- ext/pg_query/extconf.rb | 4 ++-- spec/lib/fingerprint_spec.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 26efe450..f77585ab 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ task test: :spec task lint: :rubocop task :clean do - FileUtils.rm_rf File.join(File.dirname(__FILE__), 'tmp/') - FileUtils.rm_f Dir.glob(File.join(File.dirname(__FILE__), 'ext/pg_query/*.o')) - FileUtils.rm_f File.join(File.dirname(__FILE__), 'lib/pg_query/pg_query.bundle') + FileUtils.rm_rf File.join(__dir__, 'tmp/') + FileUtils.rm_f Dir.glob(File.join(__dir__, 'ext/pg_query/*.o')) + FileUtils.rm_f File.join(__dir__, 'lib/pg_query/pg_query.bundle') end diff --git a/ext/pg_query/extconf.rb b/ext/pg_query/extconf.rb index 4418a2c5..1d9a70da 100644 --- a/ext/pg_query/extconf.rb +++ b/ext/pg_query/extconf.rb @@ -7,7 +7,7 @@ workdir = Dir.pwd libdir = File.join(workdir, 'libpg_query-' + LIB_PG_QUERY_TAG) -gemdir = File.join(File.dirname(__FILE__), '../..') +gemdir = File.join(__dir__, '../..') libfile = libdir + '/libpg_query.a' unless File.exist?("#{workdir}/libpg_query.tar.gz") @@ -36,7 +36,7 @@ $LIBPATH << libdir $CFLAGS << " -I #{libdir} -O3 -Wall -fno-strict-aliasing -fwrapv -g" -SYMFILE = File.join(File.dirname(__FILE__), 'pg_query_ruby.sym') +SYMFILE = File.join(__dir__, 'pg_query_ruby.sym') if RUBY_PLATFORM =~ /darwin/ $DLDFLAGS << " -Wl,-exported_symbols_list #{SYMFILE}" unless defined?(::Rubinius) else diff --git a/spec/lib/fingerprint_spec.rb b/spec/lib/fingerprint_spec.rb index 43578cca..ac44d420 100644 --- a/spec/lib/fingerprint_spec.rb +++ b/spec/lib/fingerprint_spec.rb @@ -25,7 +25,7 @@ def fingerprint_parts(qstr) end def fingerprint_defs - @fingerprint_defs ||= JSON.parse File.read(File.join(File.dirname(__FILE__), '../files/fingerprint.json')) + @fingerprint_defs ||= JSON.parse File.read(File.join(__dir__, '../files/fingerprint.json')) end describe PgQuery, "#fingerprint" do