Skip to content

Commit

Permalink
renamed var bin => name
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Mar 2, 2014
1 parent 72ad4b4 commit 922cf52
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/image_optim/bin_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def initialize
@lock = Mutex.new
end

def resolve!(bin)
bin = bin.to_sym
resolving(bin) do
@bins[bin] = resolve?(bin)
def resolve!(name)
name = name.to_sym
resolving(name) do
@bins[name] = resolve?(name)
end
@bins[bin] or raise BinNotFoundError, "`#{bin}` not found"
@bins[name] or raise BinNotFoundError, "`#{name}` not found"
end

VENDOR_PATH = File.expand_path('../../../vendor', __FILE__)
Expand All @@ -26,30 +26,30 @@ def env_path

private

def resolving(bin)
unless @bins.include?(bin)
def resolving(name)
unless @bins.include?(name)
@lock.synchronize do
unless @bins.include?(bin)
unless @bins.include?(name)
yield
end
end
end
end

def resolve?(bin)
if path = ENV["#{bin}_bin".upcase]
def resolve?(name)
if path = ENV["#{name}_bin".upcase]
unless @dir
@dir = FSPath.temp_dir
at_exit{ FileUtils.remove_entry_secure @dir }
end
symlink = @dir / bin
symlink = @dir / name
symlink.make_symlink(File.expand_path(path))
end
accessible?(bin)
accessible?(name)
end

def accessible?(bin)
capture_output("which #{bin.to_s.shellescape}") != ''
def accessible?(name)
capture_output("which #{name.to_s.shellescape}") != ''
end

def capture_output(command)
Expand Down

0 comments on commit 922cf52

Please sign in to comment.