Skip to content

Commit

Permalink
use guard clause in symlink_custom_bin!
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Oct 2, 2014
1 parent e484ba3 commit 5216360
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/image_optim/bin_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,19 @@ def resolving(name)

def symlink_custom_bin!(name)
env_name = "#{name}_bin".upcase
if (path = ENV[env_name])
path = File.expand_path(path)
desc = "`#{path}` specified in #{env_name}"
fail "#{desc} doesn\'t exist" unless File.exist?(path)
fail "#{desc} is not a file" unless File.file?(path)
fail "#{desc} is not executable" unless File.executable?(path)
unless @dir
@dir = FSPath.temp_dir
at_exit{ FileUtils.remove_entry_secure @dir }
end
symlink = @dir / name
symlink.make_symlink(path)
path = ENV[env_name]
return unless path
path = File.expand_path(path)
desc = "`#{path}` specified in #{env_name}"
fail "#{desc} doesn\'t exist" unless File.exist?(path)
fail "#{desc} is not a file" unless File.file?(path)
fail "#{desc} is not executable" unless File.executable?(path)
unless @dir
@dir = FSPath.temp_dir
at_exit{ FileUtils.remove_entry_secure @dir }
end
symlink = @dir / name
symlink.make_symlink(path)
end

# Return full path to bin or null
Expand Down

0 comments on commit 5216360

Please sign in to comment.