Module: Tracetool::Env
- Defined in:
- lib/tracetool/utils/env.rb
Overview
Utility methods for working with environment
Class Method Summary collapse
-
.ensure_atos ⇒ Object
Checks if ‘atos` can be found in path.
-
.ensure_command(cmd) ⇒ Object
Raises exception if can’t find executable in path.
-
.ensure_ndk_stack ⇒ Object
Checks if ‘ndk-stack` can be found in path.
-
.which(cmd) ⇒ Object
Finds executable in path.
Class Method Details
.ensure_atos ⇒ Object
Checks if ‘atos` can be found in path
29 30 31 |
# File 'lib/tracetool/utils/env.rb', line 29 def ensure_atos ensure_command('atos') end |
.ensure_command(cmd) ⇒ Object
Raises exception if can’t find executable in path
17 18 19 |
# File 'lib/tracetool/utils/env.rb', line 17 def ensure_command(cmd) raise(ArgumentError, "#{cmd} not found in PATH") unless which(cmd) end |
.ensure_ndk_stack ⇒ Object
Checks if ‘ndk-stack` can be found in path
23 24 25 |
# File 'lib/tracetool/utils/env.rb', line 23 def ensure_ndk_stack ensure_command('ndk-stack') end |
.which(cmd) ⇒ Object
Finds executable in path
6 7 8 9 10 11 12 13 |
# File 'lib/tracetool/utils/env.rb', line 6 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] candidates = ENV['PATH'].split(File::PATH_SEPARATOR).flat_map do |path| exts.map { |ext| File.join(path, "#{cmd}#{ext}") } end candidates.find { |exe| File.executable?(exe) && !File.directory?(exe) } end |