fix File and Dir exists? vs. exist?
parent
8d872b15b6
commit
4331625272
|
|
@ -1,7 +1,7 @@
|
||||||
module Squib::Args::DirValidator
|
module Squib::Args::DirValidator
|
||||||
|
|
||||||
def ensure_dir_created(dir)
|
def ensure_dir_created(dir)
|
||||||
unless Dir.exists?(dir)
|
unless Dir.exist?(dir)
|
||||||
Squib.logger.warn "Dir '#{dir}' does not exist, creating it."
|
Squib.logger.warn "Dir '#{dir}' does not exist, creating it."
|
||||||
FileUtils.mkdir_p dir
|
FileUtils.mkdir_p dir
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ module Squib::Args
|
||||||
|
|
||||||
def validate_file(arg)
|
def validate_file(arg)
|
||||||
return nil if arg.nil?
|
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)
|
File.expand_path(arg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ module Squib::Args
|
||||||
|
|
||||||
def validate_file(arg, i)
|
def validate_file(arg, i)
|
||||||
return nil if arg.nil?
|
return nil if arg.nil?
|
||||||
return File.expand_path(arg) if File.exists?(arg)
|
return File.expand_path(arg) if File.exist?(arg)
|
||||||
return File.expand_path(placeholder[i]) if File.exists?(placeholder[i].to_s)
|
return File.expand_path(placeholder[i]) if File.exist?(placeholder[i].to_s)
|
||||||
|
|
||||||
case deck_conf.img_missing.to_sym
|
case deck_conf.img_missing.to_sym
|
||||||
when :error
|
when :error
|
||||||
|
|
@ -44,7 +44,7 @@ module Squib::Args
|
||||||
def validate_placeholder(arg, _i)
|
def validate_placeholder(arg, _i)
|
||||||
# What if they specify placeholder, but it doesn't exist?
|
# What if they specify placeholder, but it doesn't exist?
|
||||||
# ...always warn... that's probably a mistake they made
|
# ...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!"
|
msg = "Image placeholder #{File.expand_path(arg)} does not exist!"
|
||||||
Squib.logger.warn msg
|
Squib.logger.warn msg
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ module Squib
|
||||||
when :memory
|
when :memory
|
||||||
Cairo::ImageSurface.new(@width, @height)
|
Cairo::ImageSurface.new(@width, @height)
|
||||||
when :svg
|
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)
|
Cairo::SVGSurface.new(svgfile, @width, @height)
|
||||||
else
|
else
|
||||||
Squib.logger.fatal "Back end not recognized: '#{backend}'"
|
Squib.logger.fatal "Back end not recognized: '#{backend}'"
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ module Squib
|
||||||
# @api private
|
# @api private
|
||||||
def self.load(file)
|
def self.load(file)
|
||||||
yaml = {}
|
yaml = {}
|
||||||
if File.exists? file
|
if File.exist? file
|
||||||
Squib::logger.info { " using config: #{file}" }
|
Squib::logger.info { " using config: #{file}" }
|
||||||
yaml = YAML.load_file(file) || {}
|
yaml = YAML.load_file(file) || {}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ module Squib
|
||||||
Squib::logger.info { " using layout(s): #{files}" }
|
Squib::logger.info { " using layout(s): #{files}" }
|
||||||
Array(files).each do |file|
|
Array(files).each do |file|
|
||||||
thefile = file
|
thefile = file
|
||||||
thefile = builtin(file) unless File.exists?(file)
|
thefile = builtin(file) unless File.exist?(file)
|
||||||
if File.exists? thefile
|
if File.exist? thefile
|
||||||
# note: YAML.load_file returns false on empty file
|
# note: YAML.load_file returns false on empty file
|
||||||
yml = layout.merge(YAML.load_file(thefile) || {})
|
yml = layout.merge(YAML.load_file(thefile) || {})
|
||||||
yml.each do |key, value|
|
yml.each do |key, value|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ describe Squib::Args::SaveBatch do
|
||||||
expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
|
expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
|
||||||
save_batch.load! opts
|
save_batch.load! opts
|
||||||
expect(save_batch).to have_attributes({ dir: ['tocreate'] })
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -25,18 +25,18 @@ describe Squib::Commands::New do
|
||||||
|
|
||||||
it 'creates a basic template on an fresh directory' do
|
it 'creates a basic template on an fresh directory' do
|
||||||
@cmd.process(['foo'], false)
|
@cmd.process(['foo'], false)
|
||||||
expect(File.exists?('foo/deck.rb')).to be true
|
expect(File.exist?('foo/deck.rb')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates an advanced template on an fresh directory' do
|
it 'creates an advanced template on an fresh directory' do
|
||||||
@cmd.process(['foo'], true)
|
@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
|
end
|
||||||
|
|
||||||
it 'creates a new template on an empty directory' do
|
it 'creates a new template on an empty directory' do
|
||||||
Dir.mkdir('foo')
|
Dir.mkdir('foo')
|
||||||
@cmd.process(['foo'], false)
|
@cmd.process(['foo'], false)
|
||||||
expect(File.exists?('foo/deck.rb')).to be true
|
expect(File.exist?('foo/deck.rb')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a new template on an empty ' do
|
it 'does not create a new template on an empty ' do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue