Module: Helpers

Overview

Module ‘Helpers’ containing assorted helper functions required elsewhere

Instance Method Summary collapse

Instance Method Details

#trunc_dir(dir, how_many) ⇒ string

will remove the FIRST ‘how_many’ root levels from a directory path ‘dir’..

Parameters:

  • dir (string)

    Path to be truncated

  • how_many (integer)

    How many levels to be dropped from path.

Returns:

  • (string)

    the properly truncated path



9
10
11
12
13
14
15
16
17
18
# File 'lib/update_repo/helpers.rb', line 9

def trunc_dir(dir, how_many)
  # make sure we don't lose any root slash if '--prune' is NOT specified
  return dir if how_many.zero?

  # convert to array then lose the first 'how_many' parts
  path_array = Pathname(dir).each_filename.to_a
  path_array = path_array.drop(how_many)
  # join it all back up again and return it
  File.join(path_array)
end