Predicate method for testing whether a path is absolute. It returns true if the pathname begins with a slash.
# File lib/path/filetest.rb, line 15 def absolute?(path) !relative?(path) end
Is a file a bin/ executable?
TODO: Make more robust. Probably needs to be fixed for Windows.
# File lib/path/filetest.rb, line 36 def bin?(fname) is_bin = command_paths.any? do |f| FileTest.exist?(File.join(f, fname)) end #is_bin ? File.basename(fname) : false is_bin ? fname : false end
Chop_basename(path) -> [pre-basename, basename] or nil
# File lib/path/filetest.rb, line 64 def chop_basename(path) base = File.basename(path) if /\A#{SEPARATOR_PAT}?\z/ =~ base return nil else return path[0, path.rindex(base)], base end end
Return a cached list of the PATH environment variable. This is a support method used by bin?
# File lib/path/filetest.rb, line 29 def command_paths @command_paths ||= ENV['PATH'].split(/[:;]/) end
Does the parent contain the child?
# File lib/path/filetest.rb, line 75 def contains?(child, parent=Dir.pwd) parent = File.expand_path(parent) child = File.expand_path(child) child.sub(parent,'') != child end
The opposite of absolute?
# File lib/path/filetest.rb, line 20 def relative?(path) while r = chop_basename(path.to_s) path, basename = r end path == '' end
Disabled; run with --debug to generate this.