From 433162527235b7951e2450e2f2bac9ef00fd10d0 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Tue, 24 Jan 2023 12:47:16 -0500 Subject: [PATCH] fix File and Dir exists? vs. exist? --- lib/squib/args/dir_validator.rb | 2 +- lib/squib/args/import.rb | 6 +++--- lib/squib/args/input_file.rb | 6 +++--- lib/squib/card.rb | 2 +- lib/squib/conf.rb | 2 +- lib/squib/layout_parser.rb | 4 ++-- spec/args/save_batch_spec.rb | 2 +- spec/commands/new_spec.rb | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/squib/args/dir_validator.rb b/lib/squib/args/dir_validator.rb index 837eaa5..611bdc6 100644 --- a/lib/squib/args/dir_validator.rb +++ b/lib/squib/args/dir_validator.rb @@ -1,7 +1,7 @@ module Squib::Args::DirValidator def ensure_dir_created(dir) - unless Dir.exists?(dir) + unless Dir.exist?(dir) Squib.logger.warn "Dir '#{dir}' does not exist, creating it." FileUtils.mkdir_p dir end diff --git a/lib/squib/args/import.rb b/lib/squib/args/import.rb index 2c0bc25..ea7eb3f 100644 --- a/lib/squib/args/import.rb +++ b/lib/squib/args/import.rb @@ -8,9 +8,9 @@ module Squib::Args end class Import - + def self.parameters - { + { data: nil, explode: 'qty', file: nil, @@ -49,7 +49,7 @@ module Squib::Args def validate_file(arg) return nil if arg.nil? - raise "File #{File.expand_path(arg)} does not exist!" unless File.exists?(arg) + raise "File #{File.expand_path(arg)} does not exist!" unless File.exist?(arg) File.expand_path(arg) end diff --git a/lib/squib/args/input_file.rb b/lib/squib/args/input_file.rb index 15f778f..79d0c07 100644 --- a/lib/squib/args/input_file.rb +++ b/lib/squib/args/input_file.rb @@ -29,8 +29,8 @@ module Squib::Args def validate_file(arg, i) return nil if arg.nil? - return File.expand_path(arg) if File.exists?(arg) - return File.expand_path(placeholder[i]) if File.exists?(placeholder[i].to_s) + return File.expand_path(arg) if File.exist?(arg) + return File.expand_path(placeholder[i]) if File.exist?(placeholder[i].to_s) case deck_conf.img_missing.to_sym when :error @@ -44,7 +44,7 @@ module Squib::Args def validate_placeholder(arg, _i) # What if they specify placeholder, but it doesn't exist? # ...always warn... that's probably a mistake they made - unless arg.nil? || File.exists?(arg) + unless arg.nil? || File.exist?(arg) msg = "Image placeholder #{File.expand_path(arg)} does not exist!" Squib.logger.warn msg return nil diff --git a/lib/squib/card.rb b/lib/squib/card.rb index a26842e..b89e3a0 100644 --- a/lib/squib/card.rb +++ b/lib/squib/card.rb @@ -34,7 +34,7 @@ module Squib when :memory Cairo::ImageSurface.new(@width, @height) when :svg - FileUtils.mkdir_p @deck.dir unless Dir.exists?(@deck.dir) + FileUtils.mkdir_p @deck.dir unless Dir.exist?(@deck.dir) Cairo::SVGSurface.new(svgfile, @width, @height) else Squib.logger.fatal "Back end not recognized: '#{backend}'" diff --git a/lib/squib/conf.rb b/lib/squib/conf.rb index 7344c26..0870eee 100644 --- a/lib/squib/conf.rb +++ b/lib/squib/conf.rb @@ -59,7 +59,7 @@ module Squib # @api private def self.load(file) yaml = {} - if File.exists? file + if File.exist? file Squib::logger.info { " using config: #{file}" } yaml = YAML.load_file(file) || {} end diff --git a/lib/squib/layout_parser.rb b/lib/squib/layout_parser.rb index b648fc1..7fa2f94 100644 --- a/lib/squib/layout_parser.rb +++ b/lib/squib/layout_parser.rb @@ -19,8 +19,8 @@ module Squib Squib::logger.info { " using layout(s): #{files}" } Array(files).each do |file| thefile = file - thefile = builtin(file) unless File.exists?(file) - if File.exists? thefile + thefile = builtin(file) unless File.exist?(file) + if File.exist? thefile # note: YAML.load_file returns false on empty file yml = layout.merge(YAML.load_file(thefile) || {}) yml.each do |key, value| diff --git a/spec/args/save_batch_spec.rb b/spec/args/save_batch_spec.rb index 2587040..9c63630 100644 --- a/spec/args/save_batch_spec.rb +++ b/spec/args/save_batch_spec.rb @@ -12,7 +12,7 @@ describe Squib::Args::SaveBatch do expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once save_batch.load! opts expect(save_batch).to have_attributes({ dir: ['tocreate'] }) - expect(Dir.exists? 'tocreate').to be true + expect(Dir.exist? 'tocreate').to be true end end end diff --git a/spec/commands/new_spec.rb b/spec/commands/new_spec.rb index c33ec0b..6cd655d 100644 --- a/spec/commands/new_spec.rb +++ b/spec/commands/new_spec.rb @@ -25,18 +25,18 @@ describe Squib::Commands::New do it 'creates a basic template on an fresh directory' do @cmd.process(['foo'], false) - expect(File.exists?('foo/deck.rb')).to be true + expect(File.exist?('foo/deck.rb')).to be true end it 'creates an advanced template on an fresh directory' do @cmd.process(['foo'], true) - expect(File.exists?('foo/src/deck.rb')).to be true + expect(File.exist?('foo/src/deck.rb')).to be true end it 'creates a new template on an empty directory' do Dir.mkdir('foo') @cmd.process(['foo'], false) - expect(File.exists?('foo/deck.rb')).to be true + expect(File.exist?('foo/deck.rb')).to be true end it 'does not create a new template on an empty ' do