Skip to content

Commit c238e0a

Browse files
committed
Add command Bundler::Stats::CLI.start(["-f", "json"]) to json output
1 parent 2ae8cf5 commit c238e0a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/rails_stats/json_formatter.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
module RailsStats
44
class JSONFormatter < StatsFormatter
55
def result
6-
@result = @statistics.map { |key, stats| stat_hash(key, stats) }
7-
6+
@result = []
7+
# Capture stdout
8+
old_stdout = $stdout
9+
$stdout = StringIO.new
10+
Bundler::Stats::CLI.start(["-f", "json"])
11+
bundler_stats_cli_json_result = $stdout.string
12+
$stdout = old_stdout
13+
14+
# Parse and append the JSON result
15+
@result << JSON.parse(bundler_stats_cli_json_result) unless bundler_stats_cli_json_result.strip.empty?
16+
17+
@result += @statistics.map { |key, stats| stat_hash(key, stats) }
818
@result << stat_hash("Code", @code_total).merge(code_test_hash) if @code_total
919
@result << stat_hash("Tests", @tests_total).merge(code_test_hash) if @tests_total
1020
@result << stat_hash("Total", @grand_total).merge(code_test_hash) if @grand_total

0 commit comments

Comments
 (0)