Module: PoiseLanguages::Utils::Which
- Extended by:
- Which
- Included in:
- PoiseLanguages::Utils, Which
- Defined in:
- lib/poise_languages/utils/which.rb
Overview
Replacement module for Chef::Mixin::Which with a slight improvement.
Class Method Summary collapse
-
.which(cmd, extra_path: %w{/bin /usr/bin /sbin /usr/sbin}, path: nil) ⇒ String, false
A replacement for Chef::Mixin::Which#which that allows using something other than an environment variable if needed.
Instance Method Summary collapse
-
#which(cmd, extra_path: %w{/bin /usr/bin /sbin /usr/sbin}, path: nil) ⇒ String, false
A replacement for Chef::Mixin::Which#which that allows using something other than an environment variable if needed.
Class Method Details
.which(cmd, extra_path: %w{/bin /usr/bin /sbin /usr/sbin}, path: nil) ⇒ String, false
A replacement for Chef::Mixin::Which#which that allows using something other than an environment variable if needed.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/poise_languages/utils/which.rb', line 34 def which(cmd, extra_path: %w{/bin /usr/bin /sbin /usr/sbin}, path: nil) # If it was already absolute, just return that. return cmd if cmd =~ /^(\/|([a-z]:)?\\)/i # Allow passing something other than the real env var. path ||= ENV['PATH'] # Based on Chef::Mixin::Which#which # Copyright 2010-2017, Chef Softare, Inc. paths = path.split(File::PATH_SEPARATOR) + extra_path paths.each do |candidate_path| filename = ::File.join(candidate_path, cmd) return filename if ::File.executable?(filename) end false end |
Instance Method Details
#which(cmd, extra_path: %w{/bin /usr/bin /sbin /usr/sbin}, path: nil) ⇒ String, false
A replacement for Chef::Mixin::Which#which that allows using something other than an environment variable if needed.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/poise_languages/utils/which.rb', line 34 def which(cmd, extra_path: %w{/bin /usr/bin /sbin /usr/sbin}, path: nil) # If it was already absolute, just return that. return cmd if cmd =~ /^(\/|([a-z]:)?\\)/i # Allow passing something other than the real env var. path ||= ENV['PATH'] # Based on Chef::Mixin::Which#which # Copyright 2010-2017, Chef Softare, Inc. paths = path.split(File::PATH_SEPARATOR) + extra_path paths.each do |candidate_path| filename = ::File.join(candidate_path, cmd) return filename if ::File.executable?(filename) end false end |