Class: ImageOptim::BinResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/image_optim/bin_resolver.rb

Constant Summary collapse

VENDOR_PATH =
File.expand_path('../../../vendor', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBinResolver

Returns a new instance of BinResolver.



8
9
10
11
# File 'lib/image_optim/bin_resolver.rb', line 8

def initialize
  @bins = {}
  @lock = Mutex.new
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



7
8
9
# File 'lib/image_optim/bin_resolver.rb', line 7

def dir
  @dir
end

Instance Method Details

#env_pathObject



25
26
27
# File 'lib/image_optim/bin_resolver.rb', line 25

def env_path
  "#{dir}:#{ENV['PATH']}:#{VENDOR_PATH}"
end

#resolve!(bin) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/image_optim/bin_resolver.rb', line 13

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