Class: ImageOptim::BinResolver

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

Defined Under Namespace

Classes: Bin, ComparableCondition, SimpleVersion

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_optim) ⇒ BinResolver

Returns a new instance of BinResolver.



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

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

Instance Method Details

#env_pathObject



49
50
51
# File 'lib/image_optim/bin_resolver.rb', line 49

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

#resolve!(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/image_optim/bin_resolver.rb', line 30

def resolve!(name)
  name = name.to_sym

  resolving(name) do
    if bin = resolve?(name) && Bin.new(name, version(name))
      $stderr << "Resolved #{bin}\n" if @image_optim.verbose?
    end
    @bins[name] = bin
  end

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