Sha256: 2d6d48bff5cba2f4070450bdf183a259f9bb7ee8034294211d886db0155ad864
Contents?: true
Size: 1.06 KB
Versions: 5
Compression:
Stored size: 1.06 KB
Contents
require 'image_optim/bin_not_found_error' require 'thread' require 'fspath' class ImageOptim class BinResolver attr_reader :dir def initialize @bins = {} @lock = Mutex.new end def resolve!(bin) bin = bin.to_sym unless @bins.include?(bin) @lock.synchronize do @bins[bin] = resolve?(bin) unless @bins.include?(bin) end end @bins[bin] or raise BinNotFoundError, "`#{bin}` not found" end VENDOR_PATH = File.expand_path('../../../vendor', __FILE__) def env_path "#{dir}:#{ENV['PATH']}:#{VENDOR_PATH}" end private def resolve?(bin) if path = ENV["#{bin}_bin".upcase] unless @dir @dir = FSPath.temp_dir at_exit{ FileUtils.remove_entry_secure @dir } end symlink = @dir / bin symlink.make_symlink(File.expand_path(path)) accessible?(symlink) else accessible?(bin) end end def accessible?(bin) `env PATH=#{env_path.shellescape} which #{bin.to_s.shellescape}` != '' end end end
Version data entries
5 entries across 5 versions & 1 rubygems