Skip to content

Commit

Permalink
Cleanup Ruby 2.1 warnings on File.exists?
Browse files Browse the repository at this point in the history
Mostly cherry-picks from master:

    commit d48222d
    Author: laurocaetano
    Date:   Fri Nov 1 18:15:53 2013 -0200

    commit 49062c1
    Author: Rashmi Yadav
    Date:   Fri Nov 1 18:07:27 2013 +0100

    commit c10a781
    Author: Arun Agrawal
    Date:   Fri Nov 1 10:39:06 2013 +0100

    commit 8161268
    Author: Arun Agrawal
    Date:   Fri Nov 1 09:49:57 2013 +0100

    commit 4d4ff53
    Author: Aaron Patterson
    Date:   Thu Oct 31 11:47:51 2013 -0700
  • Loading branch information
carlosantoniodasilva committed Dec 5, 2013
1 parent 584e753 commit 0239396
Show file tree
Hide file tree
Showing 37 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gem 'dalli', '>= 2.2.1'

# Add your own local bundler stuff
local_gemfile = File.dirname(__FILE__) + "/.Gemfile"
instance_eval File.read local_gemfile if File.exists? local_gemfile
instance_eval File.read local_gemfile if File.exist? local_gemfile

group :test do
platforms :mri_19 do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def backtrace_cleaner
def source_fragment(path, line)
return unless Rails.respond_to?(:root) && Rails.root
full_path = Rails.root.join(path)
if File.exists?(full_path)
if File.exist?(full_path)
File.open(full_path, "r") do |file|
start = [line - 3, 0].max
lines = file.each_line.drop(start).take(6)
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def method_missing(method, *arguments, &block)
def copy(destination, sources, options = {})
copied = []

FileUtils.mkdir_p(destination) unless File.exists?(destination)
FileUtils.mkdir_p(destination) unless File.exist?(destination)

destination_migrations = ActiveRecord::Migrator.migrations(destination)
last = destination_migrations.last
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/railties/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ db_namespace = namespace :db do
desc 'Load a schema.rb file into the database'
task :load => [:environment, :load_config] do
file = ENV['SCHEMA'] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'schema.rb')
if File.exists?(file)
if File.exist?(file)
load(file)
else
abort %{#{file} doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to limit the frameworks that will be loaded.}
Expand All @@ -274,7 +274,7 @@ db_namespace = namespace :db do
desc 'Clear a db/schema_cache.dump file.'
task :clear => [:environment, :load_config] do
filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema_cache.dump")
FileUtils.rm(filename) if File.exists?(filename)
FileUtils.rm(filename) if File.exist?(filename)
end
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def load_schema

load SCHEMA_ROOT + "/schema.rb"

if File.exists?(adapter_specific_schema_file)
if File.exist?(adapter_specific_schema_file)
load adapter_specific_schema_file
end
ensure
Expand Down
38 changes: 19 additions & 19 deletions activerecord/test/cases/migration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ def test_copying_migrations_without_timestamps
@existing_migrations = Dir[@migrations_path + "/*.rb"]

copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
assert File.exist?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
assert File.exist?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
assert_equal [@migrations_path + "/4_people_have_hobbies.bukkits.rb", @migrations_path + "/5_people_have_descriptions.bukkits.rb"], copied.map(&:filename)

expected = "# This migration comes from bukkits (originally 1)"
Expand All @@ -689,10 +689,10 @@ def test_copying_migrations_without_timestamps_from_2_sources
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
sources[:omg] = MIGRATIONS_ROOT + "/to_copy2"
ActiveRecord::Migration.copy(@migrations_path, sources)
assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
assert File.exists?(@migrations_path + "/6_create_articles.omg.rb")
assert File.exists?(@migrations_path + "/7_create_comments.omg.rb")
assert File.exist?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
assert File.exist?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
assert File.exist?(@migrations_path + "/6_create_articles.omg.rb")
assert File.exist?(@migrations_path + "/7_create_comments.omg.rb")

files_count = Dir[@migrations_path + "/*.rb"].length
ActiveRecord::Migration.copy(@migrations_path, sources)
Expand All @@ -707,8 +707,8 @@ def test_copying_migrations_with_timestamps

Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
expected = [@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb",
@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb"]
assert_equal expected, copied.map(&:filename)
Expand All @@ -732,10 +732,10 @@ def test_copying_migrations_with_timestamps_from_2_sources

Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
copied = ActiveRecord::Migration.copy(@migrations_path, sources)
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
assert File.exists?(@migrations_path + "/20100726101012_create_articles.omg.rb")
assert File.exists?(@migrations_path + "/20100726101013_create_comments.omg.rb")
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101012_create_articles.omg.rb")
assert File.exist?(@migrations_path + "/20100726101013_create_comments.omg.rb")
assert_equal 4, copied.length

files_count = Dir[@migrations_path + "/*.rb"].length
Expand All @@ -752,8 +752,8 @@ def test_copying_migrations_with_timestamps_to_destination_with_timestamps_in_fu

Time.travel_to(Time.utc(2010, 2, 20, 10, 10, 10)) do
ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
assert File.exists?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb")
assert File.exists?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb")
assert File.exist?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb")
assert File.exist?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb")

files_count = Dir[@migrations_path + "/*.rb"].length
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
Expand All @@ -770,7 +770,7 @@ def test_copying_migrations_preserving_magic_comments
@existing_migrations = Dir[@migrations_path + "/*.rb"]

copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/magic"})
assert File.exists?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")
assert File.exist?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")
assert_equal [@migrations_path + "/4_currencies_have_symbols.bukkits.rb"], copied.map(&:filename)

expected = "# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)"
Expand Down Expand Up @@ -827,8 +827,8 @@ def test_copying_migrations_to_non_existing_directory

Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
assert_equal 2, copied.length
end
ensure
Expand All @@ -842,8 +842,8 @@ def test_copying_migrations_to_empty_directory

Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
assert_equal 2, copied.length
end
ensure
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/tasks/oracle_rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_db_retrieves_create
assert_match(/not supported/, message)
end
end

class OracleDBDropTest < ActiveRecord::TestCase
include OracleSetupper

Expand All @@ -42,7 +42,7 @@ def test_db_retrieves_drop
assert_match(/not supported/, message)
end
end

class OracleDBCharsetAndCollationTest < ActiveRecord::TestCase
include OracleSetupper

Expand Down Expand Up @@ -71,7 +71,7 @@ def setup
def test_structure_dump
filename = "oracle.sql"
ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
assert File.exists?(filename)
assert File.exist?(filename)
ensure
FileUtils.rm_f(filename)
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/tasks/postgresql_rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_structure_dump
@connection.expects(:schema_search_path).returns("foo")

ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
assert File.exists?(filename)
assert File.exist?(filename)
ensure
FileUtils.rm(filename)
end
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/tasks/sqlite_rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def test_structure_dump
filename = "awesome-file.sql"

ActiveRecord::Tasks::DatabaseTasks.structure_dump @configuration, filename, '/rails/root'
assert File.exists?(dbfile)
assert File.exists?(filename)
assert File.exist?(dbfile)
assert File.exist?(filename)
ensure
FileUtils.rm_f(filename)
FileUtils.rm_f(dbfile)
Expand All @@ -182,7 +182,7 @@ def test_structure_load

open(filename, 'w') { |f| f.puts("select datetime('now', 'localtime');") }
ActiveRecord::Tasks::DatabaseTasks.structure_load @configuration, filename, '/rails/root'
assert File.exists?(dbfile)
assert File.exist?(dbfile)
ensure
FileUtils.rm_f(filename)
FileUtils.rm_f(dbfile)
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/core_ext/file/atomic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.atomic_write(file_name, temp_dir = Dir.tmpdir)
yield temp_file
temp_file.close

if File.exists?(file_name)
if File.exist?(file_name)
# Get original file permissions
old_stat = stat(file_name)
else
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/file_update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def execute_if_updated

def watched
@watched || begin
all = @files.select { |f| File.exists?(f) }
all = @files.select { |f| File.exist?(f) }
all.concat(Dir[@glob]) if @glob
all
end
Expand Down
4 changes: 2 additions & 2 deletions guides/bug_report_templates/action_controller_master.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unless File.exists?('Gemfile')
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
Expand Down Expand Up @@ -48,4 +48,4 @@ def test_returns_success
def app
Rails.application
end
end
end
2 changes: 1 addition & 1 deletion guides/bug_report_templates/active_record_master.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unless File.exists?('Gemfile')
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
Expand Down
2 changes: 1 addition & 1 deletion guides/code/getting_started/config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
2 changes: 1 addition & 1 deletion guides/rails_guides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def bundler?
# Note that rake sets the cwd to the one that contains the Rakefile
# being executed.
File.exists?('Gemfile')
File.exist?('Gemfile')
end

begin
Expand Down
2 changes: 1 addition & 1 deletion guides/rails_guides/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def output_path_for(output_file)
def generate?(source_file, output_file)
fin = File.join(source_dir, source_file)
fout = output_path_for(output_file)
all || !File.exists?(fout) || File.mtime(fout) < File.mtime(fin)
all || !File.exist?(fout) || File.mtime(fout) < File.mtime(fin)
end

def generate_guide(guide, output_file)
Expand Down
4 changes: 2 additions & 2 deletions guides/source/active_record_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Here's an example where we create a class with an `after_destroy` callback for a
```ruby
class PictureFileCallbacks
def after_destroy(picture_file)
if File.exists?(picture_file.filepath)
if File.exist?(picture_file.filepath)
File.delete(picture_file.filepath)
end
end
Expand All @@ -308,7 +308,7 @@ Note that we needed to instantiate a new `PictureFileCallbacks` object, since we
```ruby
class PictureFileCallbacks
def self.after_destroy(picture_file)
if File.exists?(picture_file.filepath)
if File.exist?(picture_file.filepath)
File.delete(picture_file.filepath)
end
end
Expand Down
4 changes: 2 additions & 2 deletions guides/source/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The `APP_PATH` constant will be used later in `rails/commands`. The `config/boot
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
```

In a standard Rails application, there's a `Gemfile` which declares all
Expand Down Expand Up @@ -117,7 +117,7 @@ when 'server'
# Change to the application's path if there is no config.ru file in current dir.
# This allows us to run `rails server` from other directories, but still get
# the main config.ru and properly set the tmp directory.
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path("config.ru"))
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))

require 'rails/commands/server'
Rails::Server.new.tap do |server|
Expand Down
2 changes: 1 addition & 1 deletion railties/bin/rails
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

git_path = File.join(File.expand_path('../../..', __FILE__), '.git')

if File.exists?(git_path)
if File.exist?(git_path)
railties_path = File.expand_path('../../lib', __FILE__)
$:.unshift(railties_path)
end
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/app_rails_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def self.exec_app_rails
end

def self.find_executable
EXECUTABLES.find { |exe| File.exists?(exe) }
EXECUTABLES.find { |exe| File.exist?(exe) }
end
end
end
2 changes: 1 addition & 1 deletion railties/lib/rails/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def env_config
# you need to load files in lib/ during the application configuration as well.
def add_lib_to_load_path! #:nodoc:
path = File.join config.root, 'lib'
$LOAD_PATH.unshift(path) if File.exists?(path)
$LOAD_PATH.unshift(path) if File.exist?(path)
end

def require_environment! #:nodoc:
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def threadsafe!
# Loads and returns the configuration of the database.
def database_configuration
yaml = paths["config/database"].first
if File.exists?(yaml)
if File.exist?(yaml)
require "erb"
YAML.load ERB.new(IO.read(yaml)).result
elsif ENV['DATABASE_URL']
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# Change to the application's path if there is no config.ru file in current directory.
# This allows us to run `rails server` from other directories, but still get
# the main config.ru and properly set the tmp directory.
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path("config.ru"))
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))

require 'rails/commands/server'
Rails::Server.new.tap do |server|
Expand Down
6 changes: 3 additions & 3 deletions railties/lib/rails/generators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def self.default_source_root
return unless base_name && generator_name
return unless default_generator_root
path = File.join(default_generator_root, 'templates')
path if File.exists?(path)
path if File.exist?(path)
end

# Returns the base root for a common set of generators. This is used to dynamically
Expand Down Expand Up @@ -365,12 +365,12 @@ def self.usage_path
source_root && File.expand_path("../USAGE", source_root),
default_generator_root && File.join(default_generator_root, "USAGE")
]
paths.compact.detect { |path| File.exists? path }
paths.compact.detect { |path| File.exist? path }
end

def self.default_generator_root
path = File.expand_path(File.join(base_name, generator_name), base_root)
path if File.exists?(path)
path if File.exist?(path)
end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def application_definition
@application_definition ||= begin

dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
unless options[:pretend] || !File.exists?(dummy_application_path)
unless options[:pretend] || !File.exist?(dummy_application_path)
contents = File.read(dummy_application_path)
contents[(contents.index(/module ([\w]+)\n(.*)class Application/m))..-1]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
Loading

0 comments on commit 0239396

Please sign in to comment.