Module: Rant::Env
Constant Summary collapse
- OS =
- RUBY =
- RUBY_BINDIR =
- RUBY_EXE =
File.join(RUBY_BINDIR, RUBY + ::Config::CONFIG["EXEEXT"])
- @@zip_bin =
false
- @@tar_bin =
false
Instance Method Summary collapse
-
#find_bin(bin_name) ⇒ Object
Searches for bin_name on path and returns an absolute path if successfull or nil if an executable called bin_name couldn’t be found.
- #have_tar? ⇒ Boolean
- #have_zip? ⇒ Boolean
- #on_windows? ⇒ Boolean
-
#pathes ⇒ Object
Get an array with all pathes in the PATH environment variable.
-
#shell_path(path) ⇒ Object
Add quotes to a path and replace File::Separators if necessary.
Instance Method Details
#find_bin(bin_name) ⇒ Object
Searches for bin_name on path and returns an absolute path if successfull or nil if an executable called bin_name couldn’t be found.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rant/init.rb', line 105 def find_bin bin_name if on_windows? bin_name_exe = nil if bin_name !~ /\.[^\.]{1,3}$/i bin_name_exe = bin_name + ".exe" end pathes.each { |dir| file = File.join(dir, bin_name) return file if test(?f, file) if bin_name_exe file = File.join(dir, bin_name_exe) return file if test(?f, file) end } else pathes.each { |dir| file = File.join(dir, bin_name) return file if test(?x, file) } end nil end |
#have_tar? ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/rant/init.rb', line 87 def have_tar? if @@tar_bin == false @@tar_bin = find_bin "tar" end !@@tar_bin.nil? end |
#have_zip? ⇒ Boolean
81 82 83 84 85 86 |
# File 'lib/rant/init.rb', line 81 def have_zip? if @@zip_bin == false @@zip_bin = find_bin "zip" end !@@zip_bin.nil? end |
#on_windows? ⇒ Boolean
76 |
# File 'lib/rant/init.rb', line 76 def on_windows?; true; end |
#pathes ⇒ Object
Get an array with all pathes in the PATH environment variable.
95 96 97 98 99 100 101 |
# File 'lib/rant/init.rb', line 95 def pathes # Windows doesn't care about case in environment variables, # but the ENV hash does! path = ENV[on_windows? ? "Path" : "PATH"] return [] unless path path.split(on_windows? ? ";" : ":") end |
#shell_path(path) ⇒ Object
Add quotes to a path and replace File::Separators if necessary.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rant/init.rb', line 128 def shell_path path # TODO: check for more characters when deciding wheter to use # quotes. if on_windows? path = path.tr("/", "\\") if path.include? ' ' '"' + path + '"' else path end else if path.include? ' ' "'" + path + "'" else path end end end |