Class: ImageOptim::BinResolver

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

Defined Under Namespace

Classes: Bin

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.



21
22
23
24
# File 'lib/image_optim/bin_resolver.rb', line 21

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



20
21
22
# File 'lib/image_optim/bin_resolver.rb', line 20

def dir
  @dir
end

Instance Method Details

#env_pathObject



42
43
44
# File 'lib/image_optim/bin_resolver.rb', line 42

def env_path
  [dir, ENV['PATH'], VENDOR_PATH].compact.join(':')
end

#resolve!(name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/image_optim/bin_resolver.rb', line 26

def resolve!(name)
  name = name.to_sym

  resolving(name) do
    @bins[name] = resolve?(name) && Bin.new(name, version(name))
  end

  if @bins[name]
    check!(@bins[name])
  else
    raise BinNotFoundError, "`#{name}` not found"
  end
end