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

Overview

Handles resolving binaries and checking versions

If there is an environment variable XXX_BIN when resolbing xxx, then a symlink to binary will be created in a temporary directory which will be added to PATH

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.



30
31
32
33
34
# File 'lib/image_optim/bin_resolver.rb', line 30

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



29
30
31
# File 'lib/image_optim/bin_resolver.rb', line 29

def dir
  @dir
end

Instance Method Details

#env_pathObject



56
57
58
# File 'lib/image_optim/bin_resolver.rb', line 56

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

#resolve!(name) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/image_optim/bin_resolver.rb', line 36

def resolve!(name)
  name = name.to_sym

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

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