Module: LogicaCompiler::Util
- Defined in:
- lib/logica_compiler/util.rb
Class Method Summary collapse
- .command_candidates(cmd) ⇒ Object
- .executable_file?(path) ⇒ Boolean
- .find_executable_in_dir(dir, cmd) ⇒ Object
- .path_like?(value) ⇒ Boolean
- .venv_bin_dir ⇒ Object
- .which(cmd) ⇒ Object
Class Method Details
.command_candidates(cmd) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/logica_compiler/util.rb', line 20 def command_candidates(cmd) cmd = cmd.to_s candidates = [cmd] return candidates unless Gem.win_platform? && File.extname(cmd).empty? pathext = ENV.fetch("PATHEXT", "").split(";").reject(&:empty?) pathext = %w[.exe .bat .cmd] if pathext.empty? pathext.map { |ext| "#{cmd}#{ext}" } end |
.executable_file?(path) ⇒ Boolean
30 31 32 |
# File 'lib/logica_compiler/util.rb', line 30 def executable_file?(path) File.file?(path) && File.executable?(path) end |
.find_executable_in_dir(dir, cmd) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/logica_compiler/util.rb', line 34 def find_executable_in_dir(dir, cmd) dir = dir.to_s command_candidates(cmd).each do |candidate| path = File.join(dir, candidate) return path if executable_file?(path) end nil end |
.path_like?(value) ⇒ Boolean
7 8 9 10 11 12 13 14 |
# File 'lib/logica_compiler/util.rb', line 7 def path_like?(value) s = value.to_s return false if s.empty? return true if s.start_with?(".", "/", "~") separators = [File::SEPARATOR, File::ALT_SEPARATOR].compact.uniq separators.any? { |sep| s.include?(sep) } end |
.venv_bin_dir ⇒ Object
16 17 18 |
# File 'lib/logica_compiler/util.rb', line 16 def venv_bin_dir Gem.win_platform? ? "Scripts" : "bin" end |
.which(cmd) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/logica_compiler/util.rb', line 43 def which(cmd) ENV.fetch("PATH", "").split(File::PATH_SEPARATOR).each do |dir| path = find_executable_in_dir(dir, cmd) return path if path end nil end |