Skip to content

Simplify running outside of an app #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# main ([unreleased](https://github.com/fastruby/rails_stats/compare/v1.0.2...main))

*
* [FEATURE: Simplify running outside of an app](https://github.com/fastruby/rails_stats/pull/34)

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

Expand All @@ -22,4 +22,4 @@
# v1.0.1 / 2018-10-8

* [FEATURE: add more aggregate stats](https://github.com/fastruby/rails_stats/pull/5)
* [FEATURE: More detailed introspection of app](https://github.com/fastruby/rails_stats/pull/1)
* [FEATURE: More detailed introspection of app](https://github.com/fastruby/rails_stats/pull/1)
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ RailsStats mainly adds the ability to be run from outside the project in questio

### Run it outside Rails project

You will need a `Rakefile` in the directory where you call `rake` and you will
need to require `rails_stats`:
Install the gem globally with:

```ruby
# Rakefile
require "rails_stats"
```
`gem install rails_stats`

You can then run:

`rails_stats PATH_TO_APP [FORMAT]`

(the format is optional and defaults to the console formatter).

Then you can call it:

```bash
$ rake stats\[/path/to/app/\]
$ rails_stats /path/to/app/

Directory: /path/to/app/

Expand Down Expand Up @@ -48,7 +50,7 @@ Directory: /path/to/app/
### Run it on many Rails engines

```bash
$ for dir in /path/to/many/engines/*/; do bundle exec rake stats[$dir]; done
$ for dir in /path/to/many/engines/*/; do rails_stats /users/brian/examples/$dir; done
```

### Within your Rails project
Expand Down Expand Up @@ -80,7 +82,7 @@ RailsStats adds more coverage than the default.
Here are some open source Rails projects and their output.

```bash
$ bundle exec rake stats[/users/brian/examples/diaspora/]
$ rails_stats /users/brian/examples//users/brian/examples/diaspora

Directory: /users/brian/examples/diaspora

Expand Down Expand Up @@ -116,7 +118,7 @@ Directory: /users/brian/examples/diaspora
Code LOC: 19333 Test LOC: 17403 Code to Test Ratio: 1:0.9


$ bundle exec rake stats[/users/brian/examples/discourse]
$ rails_stats /users/brian/examples//users/brian/examples/discourse

Directory: /users/brian/examples/discourse

Expand Down Expand Up @@ -149,7 +151,7 @@ Directory: /users/brian/examples/discourse
Code LOC: 59738 Test LOC: 28167 Code to Test Ratio: 1:0.5


$ bundle exec rake stats[/users/brian/examples/gitlabhq]
$ rails_stats /users/brian/examples//users/brian/examples/gitlabhq

Directory: /users/brian/examples/gitlabhq

Expand Down Expand Up @@ -188,7 +190,7 @@ Directory: /users/brian/examples/gitlabhq
Code LOC: 20039 Test LOC: 24857 Code to Test Ratio: 1:1.2


$ bundle exec rake stats[/users/brian/examples/redmine/]
$ rails_stats /users/brian/examples//users/brian/examples/redmine/

Directory: /users/brian/examples/redmine

Expand All @@ -212,7 +214,7 @@ Directory: /users/brian/examples/redmine
Code LOC: 31437 Test LOC: 42912 Code to Test Ratio: 1:1.4


$ bundle exec rake stats[/users/brian/examples/refinerycms]
$ rails_stats /users/brian/examples//users/brian/examples/refinerycms

Directory: /users/brian/examples/refinerycms

Expand Down Expand Up @@ -240,7 +242,7 @@ Directory: /users/brian/examples/refinerycms
Code LOC: 5447 Test LOC: 5219 Code to Test Ratio: 1:1.0


$ bundle exec rake stats[/users/brian/examples/spree]
$ rails_stats /users/brian/examples//users/brian/examples/spree

Directory: /users/brian/examples/spree

Expand Down
9 changes: 9 additions & 0 deletions exe/rails_stats
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "rails_stats/all"

root_directory = ARGV[0]
fmt = ARGV[1] || ""

RailsStats::CodeStatistics.new(root_directory, {format: fmt}).to_s
4 changes: 1 addition & 3 deletions lib/rails_stats/console_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
module RailsStats
class ConsoleFormatter < StatsFormatter
def to_s
Bundler::Stats::CLI.start
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etagwerker I saw that you added this in #21

It was causing me trouble because Bundler was trying to interpret the first command line argument as a Bundler command.

The gem reporting seems to still work without it, so perhaps it was only needed for an older version of Bundler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I think it's not correctly counting the gems, I'll need to dig into this a bit more.

Copy link

Choose a reason for hiding this comment

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

This issue is the same as reported in #30. I'm getting that too.


print_header
sorted_keys = @statistics.keys.sort
sorted_keys.each { |key| print_line(key, @statistics[key]) }
Expand Down Expand Up @@ -54,4 +52,4 @@ def print_code_test_stats
puts ""
end
end
end
end
2 changes: 1 addition & 1 deletion rails_stats.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to match the newer Bundler convention.

spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

Expand Down
Loading