Class: UpdateRepo::Metrics

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

Overview

Class : Metrics. This class takes care of storing the metrics for processed, failures, etc.

Instance Method Summary collapse

Methods included from Helpers

#trunc_dir

Constructor Details

#initialize(logger) ⇒ instance

Constructor for the Metrics class.

Parameters:

  • logger (instance)

    Pointer to the Logger class



13
14
15
16
17
# File 'lib/update_repo/metrics.rb', line 13

def initialize(logger)
  @log = logger
  @metrics = { processed: 0, skipped: 0, failed: 0, updated: 0,
               start_time: 0, failed_list: [] }
end

Instance Method Details

#[](key) ⇒ various

Read the metric ‘key’

Parameters:

  • key (symbol)

    the key to read

Returns:

  • (various)

    Return the value for hash key ‘key’



22
23
24
# File 'lib/update_repo/metrics.rb', line 22

def [](key)
  @metrics[key]
end

#[]=(key, value) ⇒ value

Set the metric ‘key’ to ‘value’

Parameters:

  • key (symbol)

    the key to set

  • value (symbol)

    set ‘key’ to this value.

Returns:

  • (value)

    Return the value set.



30
31
32
# File 'lib/update_repo/metrics.rb', line 30

def []=(key, value)
  @metrics[key] = value
end

#handle_err(line) ⇒ void

This method returns an undefined value.

output an error line and update the metrics

Parameters:

  • line (string)

    The string containing the error message



37
38
39
40
41
42
43
# File 'lib/update_repo/metrics.rb', line 37

def handle_err(line)
  return unless line =~ /^fatal:|^error:/
  print_log '   ', line.red
  @metrics[:failed] += 1
  err_loc = Dir.pwd + " (#{repo_url})"
  @metrics[:failed_list].push(loc: err_loc, line: line)
end

#handle_output(line) ⇒ void

This method returns an undefined value.

print a git output line and update the metrics if an update has occurred

Parameters:

  • line (string)

    The string containing the git output line



48
49
50
51
# File 'lib/update_repo/metrics.rb', line 48

def handle_output(line)
  print_log '   ', line.cyan
  @metrics[:updated] += 1 if line =~ %r{^From\s(?:https?|git)://}
end