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: BadBinVersion, Bin, BinNotFound, ComparableCondition, Error, 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



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

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

Instance Method Details

#env_pathObject



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

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

#resolve!(name) ⇒ Object



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

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 BinNotFound, "`#{name}` not found"
  end
end