Module: RSCM::PathConverter

Included in:
Subversion
Defined in:
lib/rscm/path_converter.rb

Class Method Summary collapse

Class Method Details

.ensure_trailing_slash(url) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/rscm/path_converter.rb', line 66

def ensure_trailing_slash(url)
  return nil if url.nil?
  if(url && url[-1..-1] != "/")
    "#{url}/"
  else
    url
  end
end

.filepath_to_nativepath(path, escaped) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rscm/path_converter.rb', line 25

def filepath_to_nativepath(path, escaped)
  return nil if path.nil?
  path = File.expand_path(path)
  if(WIN32)
    path.gsub(/\//, "\\")
  elsif(CYGWIN)
    cmd = "cygpath --windows #{path}"
    Better.popen(cmd) do |io|
      cygpath = io.read.chomp
      escaped ? cygpath.gsub(/\\/, "\\\\\\\\") : cygpath
    end
  else
    path
  end
end

.filepath_to_nativeurl(path) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/rscm/path_converter.rb', line 41

def filepath_to_nativeurl(path)
  return nil if path.nil?
  if(WINDOWS)
    urlpath = filepath_to_nativepath(path, false).gsub(/\\/, "/")
    "file:///#{urlpath}"
  else
    "file://#{File.expand_path(path)}"
  end
end

.nativepath_to_filepath(path) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rscm/path_converter.rb', line 51

def nativepath_to_filepath(path)
  return nil if path.nil?
  if(WIN32)
    path.gsub(/\//, "\\")
  elsif(CYGWIN)
    path = path.gsub(/\\/, "/")
    cmd = "cygpath --unix #{path}"
    Better.popen(cmd) do |io|
      io.read.chomp
    end
  else
    path
  end
end