Class: RailsStats::JSONFormatter
Instance Attribute Summary
#calculator
Instance Method Summary
collapse
#initialize
Instance Method Details
#result ⇒ Object
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_s ⇒ Object
28
29
30
|
# File 'lib/rails_stats/json_formatter.rb', line 28
def to_s
puts JSON.generate(result, ascii_only: false)
end
|