module Chef::Mixin::Which
Public Instance Methods
where(*cmds, extra_path: nil, &block)
click to toggle source
# File lib/chef/mixin/which.rb, line 25 def where(*cmds, extra_path: nil, &block) # NOTE: unnecessarily duplicates function of path_sanity extra_path ||= [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ] paths = env_path.split(File::PATH_SEPARATOR) + Array(extra_path) cmds.map do |cmd| paths.map do |path| filename = Chef.path_to(File.join(path, cmd)) filename if valid_executable?(filename, &block) end.compact end.flatten end
which(*cmds, extra_path: nil, &block)
click to toggle source
# File lib/chef/mixin/which.rb, line 21 def which(*cmds, extra_path: nil, &block) where(*cmds, extra_path: extra_path, &block).first || false end
Private Instance Methods
env_path()
click to toggle source
for test stubbing
# File lib/chef/mixin/which.rb, line 40 def env_path ENV["PATH"] end
valid_executable?(filename) { |filename| ... }
click to toggle source
# File lib/chef/mixin/which.rb, line 44 def valid_executable?(filename, &block) return false unless File.executable?(filename) && !File.directory?(filename) block ? yield(filename) : true end