Skip to content

Commit 2f55046

Browse files
committed
Simplify running outside of an app
1 parent 00ccb50 commit 2f55046

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# main ([unreleased](https://github.com/fastruby/rails_stats/compare/v1.0.2...main))
22

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

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

@@ -22,4 +22,4 @@
2222
# v1.0.1 / 2018-10-8
2323

2424
* [FEATURE: add more aggregate stats](https://github.com/fastruby/rails_stats/pull/5)
25-
* [FEATURE: More detailed introspection of app](https://github.com/fastruby/rails_stats/pull/1)
25+
* [FEATURE: More detailed introspection of app](https://github.com/fastruby/rails_stats/pull/1)

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ RailsStats mainly adds the ability to be run from outside the project in questio
88

99
### Run it outside Rails project
1010

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

14-
```ruby
15-
# Rakefile
16-
require "rails_stats"
17-
```
13+
`gem install rails_stats`
14+
15+
You can then run:
16+
17+
`rails_stats PATH_TO_APP [FORMAT]`
18+
19+
(the format is optional and defaults to the console formatter).
1820

1921
Then you can call it:
2022

2123
```bash
22-
$ rake stats\[/path/to/app/\]
24+
$ rails_stats /path/to/app/
2325

2426
Directory: /path/to/app/
2527

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

5052
```bash
51-
$ for dir in /path/to/many/engines/*/; do bundle exec rake stats[$dir]; done
53+
$ for dir in /path/to/many/engines/*/; do rails_stats /users/brian/examples/$dir; done
5254
```
5355

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

8284
```bash
83-
$ bundle exec rake stats[/users/brian/examples/diaspora/]
85+
$ rails_stats /users/brian/examples//users/brian/examples/diaspora
8486

8587
Directory: /users/brian/examples/diaspora
8688

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

118120

119-
$ bundle exec rake stats[/users/brian/examples/discourse]
121+
$ rails_stats /users/brian/examples//users/brian/examples/discourse
120122

121123
Directory: /users/brian/examples/discourse
122124

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

151153

152-
$ bundle exec rake stats[/users/brian/examples/gitlabhq]
154+
$ rails_stats /users/brian/examples//users/brian/examples/gitlabhq
153155

154156
Directory: /users/brian/examples/gitlabhq
155157

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

190192

191-
$ bundle exec rake stats[/users/brian/examples/redmine/]
193+
$ rails_stats /users/brian/examples//users/brian/examples/redmine/
192194

193195
Directory: /users/brian/examples/redmine
194196

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

214216

215-
$ bundle exec rake stats[/users/brian/examples/refinerycms]
217+
$ rails_stats /users/brian/examples//users/brian/examples/refinerycms
216218

217219
Directory: /users/brian/examples/refinerycms
218220

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

242244

243-
$ bundle exec rake stats[/users/brian/examples/spree]
245+
$ rails_stats /users/brian/examples//users/brian/examples/spree
244246

245247
Directory: /users/brian/examples/spree
246248

exe/rails_stats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ruby
2+
3+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4+
require "rails_stats/all"
5+
6+
root_directory = ARGV[0]
7+
fmt = ARGV[1] || ""
8+
9+
RailsStats::CodeStatistics.new(root_directory, {format: fmt}).to_s

lib/rails_stats/console_formatter.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
module RailsStats
44
class ConsoleFormatter < StatsFormatter
55
def to_s
6-
Bundler::Stats::CLI.start
7-
86
print_header
97
sorted_keys = @statistics.keys.sort
108
sorted_keys.each { |key| print_line(key, @statistics[key]) }
@@ -54,4 +52,4 @@ def print_code_test_stats
5452
puts ""
5553
end
5654
end
57-
end
55+
end

rails_stats.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
1414
spec.license = "MIT"
1515

1616
spec.files = `git ls-files -z`.split("\x0")
17-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
1818
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1919
spec.require_paths = ["lib"]
2020

0 commit comments

Comments
 (0)