Browse Source

fix File and Dir exists? vs. exist?

dev
Andy Meneely 3 years ago
parent
commit
4331625272
  1. 2
      lib/squib/args/dir_validator.rb
  2. 6
      lib/squib/args/import.rb
  3. 6
      lib/squib/args/input_file.rb
  4. 2
      lib/squib/card.rb
  5. 2
      lib/squib/conf.rb
  6. 4
      lib/squib/layout_parser.rb
  7. 2
      spec/args/save_batch_spec.rb
  8. 6
      spec/commands/new_spec.rb

2
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

6
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

6
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

2
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}'"

2
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

4
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|

2
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

6
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

Loading…
Cancel
Save