Class: Foundries::Recording::Reporter
- Inherits:
-
Object
- Object
- Foundries::Recording::Reporter
- Defined in:
- lib/foundries/recording/reporter.rb
Constant Summary collapse
- MAX_STDOUT_CANDIDATES =
10
Class Method Summary collapse
Instance Method Summary collapse
- #candidates ⇒ Object
-
#initialize(results:, total_creates:, total_tests:) ⇒ Reporter
constructor
A new instance of Reporter.
- #summary(json_path: nil) ⇒ Object
- #write_json(path) ⇒ Object
Constructor Details
#initialize(results:, total_creates:, total_tests:) ⇒ Reporter
Returns a new instance of Reporter.
49 50 51 52 53 |
# File 'lib/foundries/recording/reporter.rb', line 49 def initialize(results:, total_creates:, total_tests:) @results = results @total_creates = total_creates @total_tests = total_tests end |
Class Method Details
.merge_files(paths, output_path:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/foundries/recording/reporter.rb', line 14 def self.merge_files(paths, output_path:) combined_per_test = {} total_creates = 0 paths.each do |path| data = JSON.parse(File.read(path)) total_creates += data["total_factory_creates"] data["per_test"].each do |test_id, test_data| combined_per_test[test_id] = test_data end end total_tests = combined_per_test.size results = combined_per_test.transform_values do |test_data| children = (test_data["tree"] || []).map { |h| node_from_hash(h) } Node.new(factory: :__root__, children: children) end reporter = new(results: results, total_creates: total_creates, total_tests: total_tests) reporter.write_json(output_path) reporter.summary(json_path: output_path) end |
Instance Method Details
#candidates ⇒ Object
55 56 57 |
# File 'lib/foundries/recording/reporter.rb', line 55 def candidates @candidates ||= Aggregator.new(@results).candidates end |
#summary(json_path: nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/foundries/recording/reporter.rb', line 64 def summary(json_path: nil) lines = [] lines << "[Foundries] Recording complete. #{@total_tests} tests, #{@total_creates} factory creates." if candidates.empty? lines << "[Foundries] No preset candidates found." else lines << "[Foundries] Top preset candidates:" candidates.first(MAX_STDOUT_CANDIDATES).each_with_index do |candidate, index| lines << " #{index + 1}. #{candidate[:structure]} (#{candidate[:frequency]} tests, score: #{candidate[:score]})" end end lines << "[Foundries] Full report: #{json_path}" if json_path lines.join("\n") end |
#write_json(path) ⇒ Object
59 60 61 62 |
# File 'lib/foundries/recording/reporter.rb', line 59 def write_json(path) FileUtils.mkdir_p(File.dirname(path)) File.write(path, JSON.pretty_generate(json_data)) end |