module Gem::Util
This module contains various utility methods as module methods.
Public Class Methods
Source
# File lib/rubygems/util.rb, line 111defself.correct_for_windows_path(path)ifpath[0].chr=="/"&&path[1].chr.match?(/[a-z]/i)&&path[2].chr==":"path[1..-1]elsepathendend
Correctspath (usually returned by ‘Gem::URI.parse().path` on Windows), that comes with a leading slash.
Source
# File lib/rubygems/util.rb, line 103defself.glob_files_in_dir(glob,base_path)Dir.glob(glob,base:base_path).map! {|f|File.expand_path(f,base_path) }end
Globs for files matchingpattern inside ofdirectory, returning absolute paths to the matching files.
Source
# File lib/rubygems/util.rb, line 12defself.gunzip(data)require"zlib"require"stringio"data =StringIO.new(data,"r")gzip_reader =beginZlib::GzipReader.new(data)rescueZlib::GzipFile::Error=>eraisee.class,e.inspect,e.backtraceendunzipped =gzip_reader.readunzipped.force_encodingEncoding::BINARYunzippedend
Zlib::GzipReader wrapper that unzipsdata.
Source
# File lib/rubygems/util.rb, line 31defself.gzip(data)require"zlib"require"stringio"zipped =StringIO.new(String.new,"w")zipped.set_encodingEncoding::BINARYZlib::GzipWriter.wrapzippeddo|io|io.writedataendzipped.stringend
Zlib::GzipWriter wrapper that zipsdata.
Source
# File lib/rubygems/util.rb, line 47defself.inflate(data)require"zlib"Zlib::Inflate.inflatedataend
AZlib::Inflate#inflate wrapper
Source
# File lib/rubygems/util.rb, line 55defself.popen(*command)IO.popencommand,&:readend
This callsIO.popen and reads the result
Source
# File lib/rubygems/util.rb, line 62defself.silent_system(*command)opt = {out:IO::NULL,err: [:child,:out] }ifHash===command.lastopt.update(command.last)cmds =command[0...-1]elsecmds =command.dupendsystem(*(cmds<<opt))end
Invokes system, but silences all output.
Source
# File lib/rubygems/util.rb, line 82defself.traverse_parents(directory,&block)returnenum_for__method__,directoryunlessblock_given?here =File.expand_pathdirectoryloopdobeginDir.chdirhere,&blockrescueStandardErrorErrno::EACCESendnew_here =File.expand_path("..",here)returnifnew_here==here# toplevelhere =new_hereendend
Enumerates the parents ofdirectory.