Class: UpdateRepo::Metrics
- Inherits:
-
Object
- Object
- UpdateRepo::Metrics
- 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
-
#[](key) ⇒ various
Read the metric ‘key’.
-
#[]=(key, value) ⇒ value
Set the metric ‘key’ to ‘value’.
-
#handle_err(line) ⇒ void
output an error line and update the metrics.
-
#handle_output(line) ⇒ void
print a git output line and update the metrics if an update has occurred.
-
#initialize(logger) ⇒ instance
constructor
Constructor for the Metrics class.
Methods included from Helpers
Constructor Details
#initialize(logger) ⇒ instance
Constructor for the Metrics 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’
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’
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
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
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 |