Class: RailsStats::JSONFormatter

Inherits:
StatsFormatter show all
Defined in:
lib/rails_stats/json_formatter.rb

Instance Attribute Summary

Attributes inherited from StatsFormatter

#calculator

Instance Method Summary collapse

Methods inherited from StatsFormatter

#initialize

Constructor Details

This class inherits a constructor from RailsStats::StatsFormatter

Instance Method Details

#resultObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_stats/json_formatter.rb', line 5

def result
  @result = []
  old_stdout = $stdout
  $stdout = StringIO.new
  Bundler::Stats::CLI.start(["-f", "json"])
  bundler_stats_cli_json_result = $stdout.string
  $stdout = old_stdout

  @result << JSON.parse(bundler_stats_cli_json_result) unless bundler_stats_cli_json_result.strip.empty?

  @result += @statistics.map { |key, stats| stat_hash(key, stats) }
  @result << stat_hash("Code", @code_total).merge(code_test_hash) if @code_total
  @result << stat_hash("Tests", @tests_total).merge(code_test_hash) if @tests_total
  @result << stat_hash("Total", @grand_total).merge(code_test_hash) if @grand_total

  @result << { "packs" => packs_breakdown } if calculator.packs?

  @result << { "schema_stats" => schema_info }
  @result << { "polymorphic_stats" => print_polymorphic_stats }

  @result
end

#to_sObject



28
29
30
# File 'lib/rails_stats/json_formatter.rb', line 28

def to_s
  puts JSON.generate(result, ascii_only: false)
end