Class: UpdateRepo::ConsoleOutput

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/update_repo/console_output.rb

Overview

Class : ConsoleOutput. This class has functions to print header, footer and metrics.

Instance Method Summary collapse

Methods included from Helpers

#trunc_dir

Constructor Details

#initialize(logger, metrics, config) ⇒ void

Constructor for the ConsoleOutput class.

Examples:

console = ConsoleOutput.new(@log)

Parameters:

  • logger (class)

    Pointer to the Logger class

  • metrics (class)

    Pointer to the Metrics class

  • config (class)

    Pointer to the Confoog class



17
18
19
20
21
22
23
# File 'lib/update_repo/console_output.rb', line 17

def initialize(logger, metrics, config)
  @summary = { processed: 'green', updated: 'cyan', skipped: 'yellow',
               failed: 'red' }
  @metrics = metrics
  @log = logger
  @config = config.getconfig
end

Instance Method Details

#list_exceptionsvoid

This method returns an undefined value.

Print a list of any defined expections that will not be updated.

Parameters:

  • (none)


84
85
86
87
88
89
# File 'lib/update_repo/console_output.rb', line 84

def list_exceptions
  exceptions = @config['exceptions']
  return unless exceptions
  print_log "\nExclusions:".underline, ' ',
            exceptions.join(', ').yellow, "\n"
end

#list_failuresvoid

This method returns an undefined value.

List any repositories that failed their update, and the error.

Parameters:

  • (none)


72
73
74
75
76
77
78
79
# File 'lib/update_repo/console_output.rb', line 72

def list_failures
  print_log "\n\n!! Note : The following #{@metrics[:failed_list].count}",
            ' repositories ', 'FAILED'.red.underline, ' during this run :'
  @metrics[:failed_list].each do |failed|
    print_log "\n  [", 'x'.red, "] #{failed[:loc]}"
    print_log "\n    -> ", "\"#{failed[:line].chomp}\"".red
  end
end

#list_locationsvoid

This method returns an undefined value.

Print a list of all top-level directories that will be searched and any Git repos contained within updated.



94
95
96
97
98
99
# File 'lib/update_repo/console_output.rb', line 94

def list_locations
  print_log "\nRepo location(s):\n".underline
  @config['location'].each do |loc|
    print_log '-> ', loc.cyan, "\n"
  end
end

This method returns an undefined value.

Print end-of-run metrics to console / log

Parameters:

  • (none)


59
60
61
62
63
64
65
66
67
# File 'lib/update_repo/console_output.rb', line 59

def print_metrics
  @summary.each do |metric, color|
    metric_value = @metrics[metric]
    output = "#{metric_value} #{metric.capitalize}"
    print_log ' | ', output.send(color.to_sym) unless metric_value.zero?
  end
  print_log ' |'
  list_failures unless @metrics[:failed_list].empty?
end

This method returns an undefined value.

print out a brief footer. This will be expanded later.

Parameters:

  • (none)


47
48
49
50
51
52
53
54
# File 'lib/update_repo/console_output.rb', line 47

def show_footer
  duration = Time.now - @metrics[:start_time]
  print_log "\nUpdates completed in ", show_time(duration).cyan
  print_metrics
  print_log " \n\n"
  # close the log file now as we are done, just to be sure ...
  @log.close
end

#show_headervoid

This method returns an undefined value.

Display a simple header to the console

Examples:

show_header

Parameters:

  • (none)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/update_repo/console_output.rb', line 30

def show_header
  # print an informative header before starting
  print_log "\nGit Repo update utility (v", VERSION, ')',
            " \u00A9 Grant Ramsay <[email protected]>\n"
  print_log "Using Configuration from '#{@config.config_path}'\n"
  # list out the locations that will be searched
  list_locations
  # list any exceptions that we have from the config file
  list_exceptions
  # save the start time for later display in the footer...
  @metrics[:start_time] = Time.now
  print_log "\n" # blank line before processing starts
end