Use File.exist? instead of File.exists?

We've noticed the following warning while testing the upgrade to
Ruby 3.0:

warning: File.exists? is deprecated; use File.exist? instead

We're adding a Rubocop rule so we don't call the deprecated method
in the future.
This commit is contained in:
Javi Martín
2023-01-14 22:24:08 +01:00
parent 023bc6eb59
commit 5e7b3f72a2
3 changed files with 19 additions and 16 deletions

View File

@@ -164,6 +164,9 @@ Lint/BooleanSymbol:
Lint/ConstantDefinitionInBlock: Lint/ConstantDefinitionInBlock:
Enabled: true Enabled: true
Lint/DeprecatedClassMethods:
Enabled: true
Lint/DuplicateBranch: Lint/DuplicateBranch:
Enabled: true Enabled: true

View File

@@ -95,14 +95,14 @@ class MachineLearning
def data_output_files def data_output_files
files = { tags: [], related_content: [], comments_summary: [] } files = { tags: [], related_content: [], comments_summary: [] }
files[:tags] << proposals_tags_filename if File.exists?(data_folder.join(proposals_tags_filename)) files[:tags] << proposals_tags_filename if File.exist?(data_folder.join(proposals_tags_filename))
files[:tags] << proposals_taggings_filename if File.exists?(data_folder.join(proposals_taggings_filename)) files[:tags] << proposals_taggings_filename if File.exist?(data_folder.join(proposals_taggings_filename))
files[:tags] << investments_tags_filename if File.exists?(data_folder.join(investments_tags_filename)) files[:tags] << investments_tags_filename if File.exist?(data_folder.join(investments_tags_filename))
files[:tags] << investments_taggings_filename if File.exists?(data_folder.join(investments_taggings_filename)) files[:tags] << investments_taggings_filename if File.exist?(data_folder.join(investments_taggings_filename))
files[:related_content] << proposals_related_filename if File.exists?(data_folder.join(proposals_related_filename)) files[:related_content] << proposals_related_filename if File.exist?(data_folder.join(proposals_related_filename))
files[:related_content] << investments_related_filename if File.exists?(data_folder.join(investments_related_filename)) files[:related_content] << investments_related_filename if File.exist?(data_folder.join(investments_related_filename))
files[:comments_summary] << proposals_comments_summary_filename if File.exists?(data_folder.join(proposals_comments_summary_filename)) files[:comments_summary] << proposals_comments_summary_filename if File.exist?(data_folder.join(proposals_comments_summary_filename))
files[:comments_summary] << investments_comments_summary_filename if File.exists?(data_folder.join(investments_comments_summary_filename)) files[:comments_summary] << investments_comments_summary_filename if File.exist?(data_folder.join(investments_comments_summary_filename))
files files
end end
@@ -438,13 +438,13 @@ class MachineLearning
end end
def last_modified_date_for(filename) def last_modified_date_for(filename)
return nil unless File.exists? data_folder.join(filename) return nil unless File.exist? data_folder.join(filename)
File.mtime data_folder.join(filename) File.mtime data_folder.join(filename)
end end
def updated_file?(filename) def updated_file?(filename)
return false unless File.exists? data_folder.join(filename) return false unless File.exist? data_folder.join(filename)
return true unless previous_modified_date[filename].present? return true unless previous_modified_date[filename].present?
last_modified_date_for(filename) > previous_modified_date[filename] last_modified_date_for(filename) > previous_modified_date[filename]

View File

@@ -18,8 +18,8 @@ describe "files tasks" do
travel_to(2.days.from_now) { run_rake_task } travel_to(2.days.from_now) { run_rake_task }
expect(File.exists?(image.file_path)).to be false expect(File.exist?(image.file_path)).to be false
expect(File.exists?(document.file_path)).to be false expect(File.exist?(document.file_path)).to be false
end end
it "does not delete recent cached attachments" do it "does not delete recent cached attachments" do
@@ -33,8 +33,8 @@ describe "files tasks" do
travel_to(2.minutes.from_now) { run_rake_task } travel_to(2.minutes.from_now) { run_rake_task }
expect(File.exists?(image.file_path)).to be true expect(File.exist?(image.file_path)).to be true
expect(File.exists?(document.file_path)).to be true expect(File.exist?(document.file_path)).to be true
end end
it "does not delete old regular attachments" do it "does not delete old regular attachments" do
@@ -43,8 +43,8 @@ describe "files tasks" do
travel_to(2.days.from_now) { run_rake_task } travel_to(2.days.from_now) { run_rake_task }
expect(File.exists?(image.file_path)).to be true expect(File.exist?(image.file_path)).to be true
expect(File.exists?(document.file_path)).to be true expect(File.exist?(document.file_path)).to be true
end end
end end
end end