class Natives::HostDetection::PackageProvider

Constants

COMMANDS
PROVIDERS

Public Class Methods

new(platform) click to toggle source
# File lib/natives/host_detection/package_provider.rb, line 50
def initialize(platform)
  @platform = platform
end

Public Instance Methods

name() click to toggle source
# File lib/natives/host_detection/package_provider.rb, line 54
def name
  providers = Array(PROVIDERS[@platform.name])
  return providers.first if providers.count < 2

  providers.find do |provider|
    which(COMMANDS[provider]) != nil
  end
end

Protected Instance Methods

which(cmd) click to toggle source

copied from Chef cookbook ‘apt’ source: apt/libraries/helpers.rb

# File lib/natives/host_detection/package_provider.rb, line 67
def which(cmd)
  paths = (
    ENV['PATH'].split(::File::PATH_SEPARATOR) +
    %w(/bin /usr/bin /sbin /usr/sbin /opt/local/bin)
  )

  paths.each do |path|
    possible = File.join(path, cmd)
    return possible if File.executable?(possible)
  end

  nil
end