Module: OyenCov::TestReportMerger
- Defined in:
- lib/oyencov/test_report_merger.rb
Class Method Summary collapse
- .collate_job_reports(filepath_glob, save_to = nil) ⇒ Hash
- .create_or_append!(hash_to_merge) ⇒ Object
Class Method Details
.collate_job_reports(filepath_glob, save_to = nil) ⇒ Hash
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/oyencov/test_report_merger.rb', line 27 def self.collate_job_reports(filepath_glob, save_to = nil) # Read and parse their JSONs job_reports_files = Dir.glob(filepath_glob) # binding.irb return if job_reports_files.count == 0 job_reports = job_reports_files.map do |f| JSON.parse(File.read(f)) end # Add them up collated_report = job_reports.reduce({ "controller_action_hits" => {}, "method_hits" => {} }) do |i, j| ij = {} i.keys.each do |metric| unless j[metric] ij[metric] = i[metric] next end case metric when "controller_action_hits", "method_hits" ij[metric] = add_hashes(i[metric], j[metric]) end end ij end # Persist to filesystem as JSON if !!save_to end collated_report end |
.create_or_append!(hash_to_merge) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/oyencov/test_report_merger.rb', line 8 def self.create_or_append!(hash_to_merge) resultset_path = OyenCov.config.test_resultset_path # Load hash_content = if File.exist?(resultset_path) JSON.parse(File.read(resultset_path)) else {} end hash_content.merge!(hash_to_merge) # Persist File.write(resultset_path, JSON.generate(hash_content)) end |