Module: URI
- Defined in:
- lib/gonzui/util.rb
Class Method Summary collapse
- .for_apt(package_name) ⇒ Object
- .for_cvs(repository, mozule) ⇒ Object
- .for_git(repository) ⇒ Object
- .for_svn(repository, mozule) ⇒ Object
- .from_path(path) ⇒ Object
- .path_join(*fragments) ⇒ Object
Class Method Details
.for_apt(package_name) ⇒ Object
45 46 47 |
# File 'lib/gonzui/util.rb', line 45 def for_apt(package_name) URI.parse(sprintf("apt-get://apt-get/%s", package_name)) end |
.for_cvs(repository, mozule) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gonzui/util.rb', line 49 def for_cvs(repository, mozule) if m = /^(?:(.+?)@)?(.+)$/.match(repository) prefix = m[1] root = m[2] str = sprintf("cvs://%s?module=%s", root, mozule) str << sprintf("&prefix=%s", prefix) if prefix return URI.parse(str) else raise "malformed repository: #{repository}" end end |
.for_git(repository) ⇒ Object
75 76 77 78 79 |
# File 'lib/gonzui/util.rb', line 75 def for_git(repository) uri = URI.parse(repository) uri = URI.from_path(repository) unless uri.absolute? return uri end |
.for_svn(repository, mozule) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gonzui/util.rb', line 61 def for_svn(repository, mozule) uri = URI.parse(repository) query = sprintf("module=%s", mozule) uri = URI.from_path(repository) unless uri.absolute? # replace schemes other than "svn" such as "file" and "http" # with "svn" and preserve the original scheme in a query. unless uri.scheme == "svn" query << sprintf("&original_scheme=%s", uri.scheme) uri.scheme = "svn" end uri.query = query return uri end |
.from_path(path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gonzui/util.rb', line 31 def from_path(path) path = File.(path) if (/^([a-zA-Z]:|\\\\)(.*)$/ =~ path) u = URI::Generic.new( "file", nil, $1, nil, nil, $2, nil, nil, nil, false ) def u.to_s self.host + self.path end return u else path = path.gsub(/#{Regexp.quote(File::SEPARATOR)}/, "/") return URI.parse(sprintf("file://%s", path)) end end |
.path_join(*fragments) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/gonzui/util.rb', line 21 def path_join(*fragments) if fragments.empty? return "" elsif fragments.length == 1 return fragments.fileutils else return fragments.map {|fragment| fragment.chomp("/") }.join("/") end end |