module SyncWrap::PathUtil

Utility methods for handling paths.

Private Instance Methods

path_relative_to_caller( rpath, clr ) click to toggle source

Unless rpath is already absolute, expand it relative to the calling file, as computed from passed in clr (use your Kernel#caller)

# File lib/syncwrap/path_util.rb, line 33
def path_relative_to_caller( rpath, clr ) # :doc:
  unless rpath =~ %r{^/}
    from = caller_path( clr )
    rpath = File.expand_path( rpath, from ) if from
  end
  rpath
end
relativize( path ) click to toggle source

Return path relative to PWD if the result is shorter, otherwise return input path. Preserves any trailing '/'.

# File lib/syncwrap/path_util.rb, line 43
def relativize( path ) # :doc:
  p = Pathname.new( path )
  unless p.relative?
    p = p.relative_path_from( Pathname.pwd ).to_s
    p += '/' if path[-1] == '/'
    path = p if p.length < path.length
  end
  path
end