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’.
-
#initialize ⇒ instance
constructor
Constructor for the Metrics class.
-
#load_errors(config) ⇒ void
loads an error file (if exists) into the @metrics.
-
#save_errors(config) ⇒ void
This will save any (git) errors encountered to a file, so they can be reprinted again at a later date.
Methods included from Helpers
Constructor Details
#initialize ⇒ instance
Constructor for the Metrics class. def initialize(logger)
16 17 18 19 20 |
# File 'lib/update_repo/metrics.rb', line 16 def initialize @metrics = { processed: 0, skipped: 0, failed: 0, updated: 0, unchanged: 0, start_time: 0, failed_list: [], warning: 0 } end |
Instance Method Details
#[](key) ⇒ various
Read the metric ‘key’
25 26 27 |
# File 'lib/update_repo/metrics.rb', line 25 def [](key) @metrics[key] end |
#[]=(key, value) ⇒ value
Set the metric ‘key’ to ‘value’
33 34 35 |
# File 'lib/update_repo/metrics.rb', line 33 def []=(key, value) @metrics[key] = value end |
#load_errors(config) ⇒ void
This method returns an undefined value.
loads an error file (if exists) into the @metrics.
58 59 60 61 |
# File 'lib/update_repo/metrics.rb', line 58 def load_errors(config) path = config.config_path + '.errors' @metrics[:failed_list] = YAML.load_file(path) if File.exist?(path) end |
#save_errors(config) ⇒ void
This method returns an undefined value.
This will save any (git) errors encountered to a file, so they can be reprinted again at a later date. If no errors, then delete any previously existing error file.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/update_repo/metrics.rb', line 42 def save_errors(config) # get the location of the config file, we'll use the same dir # and base name path = config.config_path + '.errors' if @metrics[:failed_list].empty? # delete any existing file if we have no errors File.delete(path) if File.exist?(path) else # otherwise save the errors to file File.open(path, 'w') { |file| file.write @metrics[:failed_list].to_yaml } end end |