Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace File.exists? with File.exist? #2170

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/features/step_definitions/command_line_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@
end

Then /an? \w+ file ([^ ]+) is (not )?removed/ do |filename, negated|
File.exists?(filename).should == !!negated
File.exist?(filename).should == !!negated
end

Then /an? \w+ file ([^ ]+) is (not )?created/ do |filename, negated|
File.exists?(filename).should == !negated
File.exist?(filename).should == !negated
end

Then "the following files are reported removed:" do |table|
Expand Down
8 changes: 4 additions & 4 deletions cli/lib/compass/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def copy(from, to, options = nil, binary = false)
def directory(dir, options = nil)
options ||= self.options if self.respond_to?(:options)
options ||= {}
if File.exists?(dir) && File.directory?(dir)
if File.exist?(dir) && File.directory?(dir)
# do nothing
elsif File.exists?(dir)
elsif File.exist?(dir)
msg = "#{basename(dir)} already exists and is not a directory."
raise Compass::FilesystemConflict.new(msg)
else
Expand All @@ -38,7 +38,7 @@ def write_file(file_name, contents, options = nil, binary = false)
options ||= self.options if self.respond_to?(:options)
skip_write = false
contents = process_erb(contents, options[:erb]) if options[:erb]
if File.exists?(file_name)
if File.exist?(file_name)
existing_contents = IO.read(file_name)
if existing_contents == contents
log_action :identical, basename(file_name), options
Expand Down Expand Up @@ -73,7 +73,7 @@ def remove(file_name)
if File.directory?(file_name)
FileUtils.rm_rf file_name
log_action :remove, basename(file_name)+"/", options
elsif File.exists?(file_name)
elsif File.exist?(file_name)
File.unlink file_name
log_action :remove, basename(file_name), options
end
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/compass/app_integration/stand_alone/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def write_configuration_files(config_file = nil)
end

def config_files_exist?
File.exists? targetize('config.rb')
File.exist? targetize('config.rb')
end

def config_contents
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/compass/commands/project_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def project_images_subdirectory
end

def assert_project_directory_exists!
if File.exists?(project_directory) && !File.directory?(project_directory)
if File.exist?(project_directory) && !File.directory?(project_directory)
raise Compass::FilesystemConflict.new("#{project_directory} is not a directory.")
elsif !File.directory?(project_directory)
raise Compass::Error.new("#{project_directory} does not exist.")
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/compass/commands/project_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def sass_columns(sass_file)
end

def css_columns(css_file)
if File.exists?(css_file)
if File.exist?(css_file)
cf = Compass::Stats::CssFile.new(css_file)
cf.analyze!
%w(selector_count prop_count file_size).map do |t|
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/compass/commands/update_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def new_config?(compiler)
return false unless config_file
config_mtime = File.mtime(config_file)
compiler.file_list.each do |(_, css_filename, _)|
return config_file if File.exists?(css_filename) && config_mtime > File.mtime(css_filename)
return config_file if File.exist?(css_filename) && config_mtime > File.mtime(css_filename)
end
nil
end
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/compass/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def new_config?
return false unless config_file
config_mtime = File.mtime(config_file)
css_files.each do |css_filename|
return config_file if File.exists?(css_filename) && config_mtime > File.mtime(css_filename)
return config_file if File.exist?(css_filename) && config_mtime > File.mtime(css_filename)
end
nil
end
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/compass/configuration/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def add_project_configuration(*args)
# Finds the configuration file, if it exists in a known location.
def detect_configuration_file(project_path = nil)
possible_files = KNOWN_CONFIG_LOCATIONS.map{|f| projectize(f, project_path) }
possible_files.detect{|f| File.exists?(f)}
possible_files.detect{|f| File.exist?(f)}
end

def handle_configuration_change!
Expand Down
4 changes: 2 additions & 2 deletions cli/lib/compass/installers/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def with_manifest(manifest_file)
# evaluated in a Manifest instance context
def parse(manifest_file)
with_manifest(manifest_file) do
if File.exists?(manifest_file)
open(manifest_file) do |f|
if File.exist?(manifest_file)
open(manifest_file) do |f|
eval(f.read, instance_binding, manifest_file)
end
else
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/compass/sass_extensions/sprites/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def file
def find_file
Compass.configuration.sprite_load_path.compact.each do |path|
f = File.join(path, relative_file)
if File.exists?(f)
if File.exist?(f)
return f
end
end
Expand Down
4 changes: 2 additions & 2 deletions cli/lib/compass/sass_extensions/sprites/sprite_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def cleanup_old_sprites

# Does this sprite need to be generated
def generation_required?
!File.exists?(filename) || outdated? || options[:force]
!File.exist?(filename) || outdated? || options[:force]
end

# Returns the uniqueness hash for this sprite object
Expand Down Expand Up @@ -109,7 +109,7 @@ def image_filenames

# Checks whether this sprite is outdated
def outdated?
if File.exists?(filename)
if File.exist?(filename)
return @images.any? {|image| image.mtime.to_i > self.mtime.to_i }
end
true
Expand Down
8 changes: 4 additions & 4 deletions cli/test/integrations/compass_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_on_stylesheet_error_callback
def test_empty_project
# With no sass files, we should have no css files.
within_project(:empty) do |proj|
return unless proj.css_path && File.exists?(proj.css_path)
return unless proj.css_path && File.exist?(proj.css_path)
Dir.new(proj.css_path).each do |f|
fail "This file should not have been generated: #{f}" unless f == "." || f == ".."
end
Expand Down Expand Up @@ -186,7 +186,7 @@ def assert_renders_correctly(*arguments)

def within_project(project_name, config_block = nil)
@current_project = project_name
Compass.add_configuration(configuration_file(project_name)) if File.exists?(configuration_file(project_name))
Compass.add_configuration(configuration_file(project_name)) if File.exist?(configuration_file(project_name))
Compass.configuration.project_path = project_path(project_name)
Compass.configuration.environment = :production
Compass.configuration.sourcemap = false unless Compass.configuration.sourcemap_set?
Expand All @@ -195,7 +195,7 @@ def within_project(project_name, config_block = nil)
config_block.call(Compass.configuration)
end

if Compass.configuration.sass_path && File.exists?(Compass.configuration.sass_path)
if Compass.configuration.sass_path && File.exist?(Compass.configuration.sass_path)
compiler = Compass.sass_compiler
compiler.logger = Compass::NullLogger.new
compiler.clean!
Expand All @@ -221,7 +221,7 @@ def each_sass_file(sass_dir = nil)

def save_output(dir)
FileUtils.rm_rf(save_path(dir))
FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exists?(tempfile_path(dir))
FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exist?(tempfile_path(dir))
end

def project_path(project_name)
Expand Down
6 changes: 3 additions & 3 deletions cli/test/units/command_line_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_print_version
def test_basic_install
within_tmp_directory do
compass(*%w(create --boring basic))
assert File.exists?("basic/sass/screen.scss")
assert File.exist?("basic/sass/screen.scss")
assert_action_performed :directory, "basic/"
assert_action_performed :create, "basic/sass/screen.scss"
end
Expand All @@ -34,8 +34,8 @@ def test_basic_install
define_method "test_#{framework.name}_installation" do
within_tmp_directory do
compass(*%W(create --boring --using #{framework.name} #{framework.name}_project))
assert File.exists?("#{framework.name}_project/sass/screen.scss"), "sass/screen.scss is missing. Found: #{Dir.glob("#{framework.name}_project/**/*").join(", ")}"
assert File.exists?("#{framework.name}_project/stylesheets/screen.css")
assert File.exist?("#{framework.name}_project/sass/screen.scss"), "sass/screen.scss is missing. Found: #{Dir.glob("#{framework.name}_project/**/*").join(", ")}"
assert File.exist?("#{framework.name}_project/stylesheets/screen.css")
assert_action_performed :directory, "#{framework.name}_project/"
assert_action_performed :create, "#{framework.name}_project/sass/screen.scss"
assert_action_performed :write, "#{framework.name}_project/stylesheets/screen.css"
Expand Down
6 changes: 3 additions & 3 deletions cli/test/units/sprites/layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def horizontal(options= {}, uri=URI)
assert_equal 400, base.width
assert_equal 60, base.height
assert_equal [[0, 0], [20, 120], [20, 0], [20, 100], [20, 160]], base.images.map {|i| [i.top, i.left]}
assert File.exists?(base.filename)
assert File.exist?(base.filename)
FileUtils.rm base.filename
end

Expand All @@ -130,7 +130,7 @@ def horizontal(options= {}, uri=URI)
assert_equal 40, base.width
assert_equal 40, base.height
assert_equal [[30, 0], [20, 10], [10, 20], [0, 30]], base.images.map {|i| [i.top, i.left]}
assert File.exists?(base.filename)
assert File.exist?(base.filename)
FileUtils.rm base.filename
end

Expand Down Expand Up @@ -173,7 +173,7 @@ def horizontal(options= {}, uri=URI)
it "should generate a horrizontal sprite" do
base = horizontal
base.generate
assert File.exists?(base.filename)
assert File.exist?(base.filename)
FileUtils.rm base.filename
end

Expand Down
4 changes: 2 additions & 2 deletions cli/test/units/sprites/sprite_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def options_to_cli(options)
def teardown
::Dir.chdir @before_dir
clean_up_sprites
if File.exists?(@test_dir)
if File.exist?(@test_dir)
::FileUtils.rm_r @test_dir
end
end

it "should create sprite file" do
assert_equal 0, run_compass_with_options(['sprite', "-f", 'stylesheet.scss', "squares/*.png"]).to_i
assert File.exists?(File.join(test_dir, 'stylesheet.scss'))
assert File.exist?(File.join(test_dir, 'stylesheet.scss'))
end

end
8 changes: 4 additions & 4 deletions cli/test/units/sprites/sprite_map_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ def teardown

it "should generate sprite" do
@base.generate
assert File.exists?(@base.filename)
assert File.exist?(@base.filename)
assert [email protected]_required?
assert [email protected]?
end

it "should remove old sprite when generating new" do
@base.generate
file = @base.filename
assert File.exists?(file), "Original file does not exist"
assert File.exist?(file), "Original file does not exist"
file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png')
FileUtils.rm file_to_remove
assert !File.exists?(file_to_remove), "Failed to remove sprite file"
assert !File.exist?(file_to_remove), "Failed to remove sprite file"
@base = sprite_map_test(@options)
@base.generate
assert !File.exists?(file), "Sprite file did not get removed"
assert !File.exist?(file), "Sprite file did not get removed"
end

test "should get correct relative_name" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ To disable the asset cache buster:
more than once. Example:

watch "images/**/*" do |project_dir, relative_path|
if File.exists?(File.join(project_dir, relative_path))
if File.exist?(File.join(project_dir, relative_path))
puts "File size of #{relative_path} is: #{File.size(File.join(project_dir, relative_path))}"
end
end
Expand All @@ -406,7 +406,7 @@ to avoid crashing the watcher in the case where the file has been removed.
**`on_sprite_saved`** -- Pass this function a block of code that gets executed after a sprite is saved to disk. The block will be passed the filename. Can be invoked more then once. Example:

on_sprite_saved do |filename|
post_process(filename) if File.exists?(filename)
post_process(filename) if File.exist?(filename)
end

**`on_sprite_generated`** -- Pass this function a block of code that gets executed after a sprite is generated but before its saved to disk. The block will be passed an instance of `ChunkyPNG::Image`. Can be invoked more then once. Example:
Expand Down
2 changes: 1 addition & 1 deletion core/lib/compass/core/sass_extensions/functions/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Compass::Core::SassExtensions::Functions::Files
def md5sum(file, format = nil)
assert_type file, :String
filename = nil
if options[:css_filename] && File.exists?(options[:css_filename])
if options[:css_filename] && File.exist?(options[:css_filename])
filename = File.expand_path(file.value, File.dirname(options[:css_filename]))
elsif Pathname.new(file.value).absolute?
filename = file.value
Expand Down
4 changes: 2 additions & 2 deletions core/lib/compass/core/sass_extensions/functions/image_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def image_dimensions(image_file)
end

def image_path_for_size(image_file)
if File.exists?(image_file)
return image_file
if File.exist?(image_file)
return image_file
end
real_path(image_file)
end
Expand Down
4 changes: 2 additions & 2 deletions core/lib/compass/frameworks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def register_directory(directory)
File.join(directory, 'lib', File.basename(directory)+".rb"),
File.join(directory, File.basename(directory)+".rb")
]
loader = loaders.detect{|l| File.exists?(l)}
loader = loaders.detect{|l| File.exist?(l)}
registered_framework = detect_registration do
require loader if loader
end
Expand All @@ -117,7 +117,7 @@ def template_usage(template)
framework = self[framework_name]
template ||= "project"
usage_file = File.join(framework.templates_directory, template, "USAGE.markdown")
if File.exists?(usage_file)
if File.exist?(usage_file)
File.read(usage_file)
elsif help = framework.manifest(template).help
help
Expand Down
4 changes: 2 additions & 2 deletions core/test/integrations/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def assert_renders_correctly(*arguments)
for name in arguments
actual_result_file = "#{tempfile_path(@current_project)}/#{name}".gsub(/s[ac]ss/, "css")
expected_result_file = "#{result_path(@current_project)}/#{name}.#{Sass.version[:major]}.#{Sass.version[:minor]}".gsub(/s[ac]ss/, "css")
expected_result_file = "#{result_path(@current_project)}/#{name}".gsub(/s[ac]ss/, "css") unless File.exists?(expected_result_file)
expected_result_file = "#{result_path(@current_project)}/#{name}".gsub(/s[ac]ss/, "css") unless File.exist?(expected_result_file)
actual_lines = File.read(actual_result_file)
actual_lines.gsub!(/^@charset[^;]+;/,'') if options[:ignore_charset]
actual_lines = actual_lines.split("\n").reject{|l| l=~/\A\Z/}
Expand Down Expand Up @@ -140,7 +140,7 @@ def each_sass_file(sass_dir = nil)

def save_output(dir)
FileUtils.rm_rf(save_path(dir))
FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exists?(tempfile_path(dir))
FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exist?(tempfile_path(dir))
end

def projects
Expand Down