Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ jobs:
gem uninstall bundler -a -x || true
- name: Install Bundler
run: |
if [[ "${{ matrix.ruby-version }}" == "2.6" || "${{ matrix.ruby-version }}" == "2.7" ]]; then
if [[ "${{ matrix.ruby-version }}" == "2.5" ]]; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gem install bundler -v "~> 2.3.27"
elif [[ "${{ matrix.ruby-version }}" == "2.6" || "${{ matrix.ruby-version }}" == "2.7" ]]; then
gem install bundler -v "~> 2.4.0"
else
gem install bundler
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# main ([unreleased](https://github.com/fastruby/rails_stats/compare/v1.0.2...main))

*
* [BUGFIX: Fix JSON output missing Code and Tests total count](https://github.com/fastruby/rails_stats/pull/40)
* Update README examples
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Update README examples
* [CHORE: Update README examples](https://github.com/fastruby/rails_stats/pull/40)


# v2.0.1 ([commits](https://github.com/fastruby/rails_stats/compare/v2.0.0...v2.0.1))

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ gemspec
group :development, :test do
gem "bundler", ">= 1.6", "< 3.0"
gem "byebug"
gem "codecov"
gem "codecov", "~> 0.6.0"
gem "minitest"
gem "minitest-around"
gem "minitest-spec-context"
gem "simplecov"
gem "simplecov", "~> 0.21"
gem "simplecov-console"
end
335 changes: 125 additions & 210 deletions README.md
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of changes in this file, is there anything in particular you would like to call out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did reduce the number of examples to 1. Also the output is a little bigger now, since we bring more information

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions lib/rails_stats/json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
module RailsStats
class JSONFormatter < StatsFormatter
def result
@result = @statistics.map { |key, stats| stat_hash(key, stats) }
@result = []
old_stdout = $stdout
$stdout = StringIO.new
Bundler::Stats::CLI.start(["-f", "json"])
bundler_stats_cli_json_result = $stdout.string
$stdout = old_stdout

if @grand_total
@result << stat_hash("Total", @grand_total).merge(code_test_hash)
end
@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
end

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

private
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/console-output.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
+-----------------------|------------|----------------+
| Name | Total Deps | 1st Level Deps |
+-----------------------|------------|----------------+
| simplecov-console | 7 | 3 |
| codecov | 5 | 2 |
| simplecov-console | 8 | 3 |
| codecov | 4 | 1 |
| rails_stats | 4 | 2 |
| simplecov | 3 | 3 |
| minitest-around | 1 | 1 |
Expand All @@ -14,14 +14,14 @@

Declared Gems 9
Total Gems 18
Unpinned Versions 8
Unpinned Versions 6
Github Refs 0

+----------------------+---------+---------+---------+---------+---------+-----+-------+
| Name | Files | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+---------+---------+---------+---------+---------+-----+-------+
| Channels | 2 | 8 | 8 | 2 | 0 | 0 | 0 |
| Configuration | 19 | 417 | 111 | 1 | 0 | 0 | 0 |
| Configuration | 19 | 417 | 111 | 1 | 0 | 0 | 0 |
| Controllers | 1 | 7 | 6 | 1 | 1 | 1 | 4 |
| Helpers | 1 | 3 | 3 | 0 | 0 | 0 | 0 |
| Javascripts | 3 | 27 | 7 | 0 | 0 | 0 | 0 |
Expand Down
Loading
Loading