Method: QB::Util.contract_path

Defined in:
lib/qb/util.rb

.contract_path(path) ⇒ Pathname

do kind of the opposite of File.expand_path -- turn the home dir into ~ and the current dir into .

Parameters:

  • path (Pathname | String)

    to contract.

Returns:

  • (Pathname)

    contracted path.



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/qb/util.rb', line 79

def self.contract_path path
  contracted = if path.start_with? Dir.pwd
    path.sub Dir.pwd, '.'
  elsif path.start_with? ENV['HOME']
    path.sub ENV['HOME'], '~'
  else
    path
  end
  
  Pathname.new contracted
end