Module: Helpers

Included in:
UpdateRepo::CmdConfig, UpdateRepo::WalkRepo
Defined in:
lib/update_repo/helpers.rb

Overview

Module ‘Helpers’ containing assorted helper functions required elsewhere

Instance Method Summary collapse

Instance Method Details

This method returns an undefined value.

this function will simply pass the given string to ‘print’, and also log to file if that is specified.

Parameters:

  • string (array)

    Array of strings for print formatting



21
22
23
24
25
26
# File 'lib/update_repo/helpers.rb', line 21

def print_log(*string)
  # log to screen regardless
  print(*string)
  # log to file if that has been enabled
  @logfile.write(string.join('').gsub(/\e\[(\d+)(;\d+)*m/, '')) if cmd('log')
end

#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



7
8
9
10
11
12
13
14
15
# File 'lib/update_repo/helpers.rb', line 7

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