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 function will simply pass the given string to ‘print’, and also log to file if that is specified.



19
20
21
22
23
24
# File 'lib/update_repo/helpers.rb', line 19

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’..



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