Sha256: 677919a2ebffa671a737bbf7ef072ed804046cdbc8399b885a1f8111fbd9548c
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 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].compact.join(':') 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)) end accessible?(bin) end def accessible?(bin) `env PATH=#{env_path.shellescape} which #{bin.to_s.shellescape}` != '' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
image_optim-0.11.2 | lib/image_optim/bin_resolver.rb |