Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# main ([unreleased](https://github.com/fastruby/rails_stats/compare/v2.1.0...main))

* [FEATURE: Add a `rails-stats` command line executable that accepts an absolute or relative directory](https://github.com/fastruby/rails_stats/pull/49)
* [FEATURE: Support component-based and Packwerk (packs) applications with a per-pack and Core breakdown](https://github.com/fastruby/rails_stats/issues/23)
* [BUGFIX: Respect an explicit path argument (e.g. `rake stats[packs/pack1]`) when running inside a booted Rails app](https://github.com/fastruby/rails_stats/issues/23)
* [CHORE: Improve the GH Test Workflow](https://github.com/fastruby/rails_stats/pull/35)
Expand Down
46 changes: 36 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,36 @@ There were a few things missing to the included `rake stats`

RailsStats mainly adds the ability to be run from outside the project in question. This can be helpful if the app you are interested in can not be booted for some reason.

### Run it outside Rails project
### Run it as a command line tool

You will need a `Rakefile` in the directory where you call `rake` and you will
need to require `rails_stats`:
Once the gem is installed you can point the `rails-stats` executable at any
directory, without setting up a `Rakefile`. It accepts both absolute and
relative paths:

```ruby
# Rakefile
require "rails_stats"
```bash
$ rails-stats /path/to/app
$ rails-stats path/to/app
```

When no path is given it defaults to the current directory:

```bash
$ rails-stats
```

You can also request JSON output by passing `json` as a second argument:

```bash
$ rails-stats path/to/app json
```

Then you can call it:
### Run it outside Rails project

The quickest way is the `rails-stats` executable, which does not require a
`Rakefile`:

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

Directory: /path/to/app/
Comment thread
Copilot marked this conversation as resolved.
Outdated

Expand Down Expand Up @@ -65,10 +81,20 @@ Directory: /path/to/app/
Code LOC: 145 Test LOC: 6 Code to Test Ratio: 1:0.0 Files: 34
```

If you would rather go through `rake`, add a `Rakefile` in the directory where
you call `rake` that requires `rails_stats`:

```ruby
# Rakefile
require "rails_stats"
```

Then call `rake stats\[/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 "$dir"; done
```

### Component-based and Packwerk (packs) applications
Expand Down Expand Up @@ -240,7 +266,7 @@ $ bundle exec rake stats[/users/brian/examples/redmine/]
If you want to export the details using JSON, you can use this command:

```
$ rake stats\[test/dummy,json\]
$ rails-stats test/dummy json

Directory: /Users/etagwerker/Projects/redmine

Expand Down
27 changes: 27 additions & 0 deletions bin/rails-stats
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Standalone CLI for running rails_stats against a directory without having to
# set up a Rakefile. Accepts both absolute and relative paths:
#
# rails-stats /path/to/app
# rails-stats path/to/app
# rails-stats # defaults to the current directory
# rails-stats path/to/app json
#
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))

require "rails_stats/all"

path = ARGV[0] || "."
format = ARGV[1] || ""

root_directory = File.absolute_path(path)

unless File.directory?(root_directory)
warn "rails-stats: no such directory - #{path}"
exit 1
end

puts "\nDirectory: #{root_directory}\n\n"
RailsStats::CodeStatistics.new(root_directory, format: format).to_s
7 changes: 4 additions & 3 deletions rails_stats.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ require 'rails_stats/version'
Gem::Specification.new do |spec|
spec.name = "rails_stats"
spec.version = RailsStats::VERSION
spec.authors = ["Brian Leonard"]
spec.email = ["brian@bleonard.com"]
spec.authors = ["Brian Leonard", "Ernesto Tagwerker"]
spec.email = ["brian@bleonard.com", "ernesto@ombulabs.com"]
spec.summary = %q{Analyze a Rails project}
spec.description = %q{Point it to a directory and see stuff about the app}
spec.homepage = "https://github.com/fastruby/rails_stats"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.bindir = "bin"
spec.executables = ["rails-stats"]
Comment on lines +17 to +18
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

Expand Down
Loading