Skip to content
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

Calculating stats for a packwere pack inside the app shows stats for the whole app unless I run it from outside the app #23

Open
oboxodo opened this issue Oct 6, 2023 · 0 comments

Comments

@oboxodo
Copy link

oboxodo commented Oct 6, 2023

Using rails_stats v1.0.2

Given I have added gem "rails_stats" to my Gemfile and I have the following app's file structure (typical when using packs-rails):

my_rails_app/
├── app
│   ├── controllers
│   └── models
├── lib
└── packs
    ├── pack1
    │   ├── app
    │   │   ├── controllers
    │   │   └── models
    │   └── lib
    └── pack2
        ├── app
        │   ├── controllers
        │   └── models
        └── lib

If I run rake stats from inside my_rails_app, it correctly shows stats including files from the main app as well as each of my packwerk packs living in packs/*:

$rake stats
+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
|...real output removed but it's correctly including all files           |
|  from . and from packs/*                                               |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  xxxx |  xxxx |    xxxx |    xxxx |  xx |    xx |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: xxx     Test LOC: xxx     Code to Test Ratio: 1:x.x

Trying to get stats about a specific pack's files, from inside the app's root directory (my_rails_app), doesn't work as expected. The stats are still calculated for the whole app, but it includes the header stating the directory too:

$rake stats[packs/pack1]

Directory: /home/oboxodo/Code/my_rails_app

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
|    ...real output removed but it's the same output                     |
|    as running it for the whole app                                     |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  xxxx |  xxxx |    xxxx |    xxxx |  xx |    xx |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: xxx     Test LOC: xxx     Code to Test Ratio: 1:x.x

Now, if I move outside the app's directory, to the parent, and I create a Rakefile with require "rails_stats", then this works as expected:

$for pack in my_rails_app/packs/*; do rake stats[$pack]; done

Directory: /home/oboxodo/Code/my_rails_app/packs/pack1

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
|...real output removed...                                               |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  xxxx |  xxxx |    xxxx |    xxxx |  xx |    xx |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: xxx     Test LOC: xxx     Code to Test Ratio: 1:x.x

Directory: /home/oboxodo/Code/my_rails_app/packs/pack2

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
|...real output removed...                                               |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  xxxx |  xxxx |    xxxx |    xxxx |  xx |    xx |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: xxx     Test LOC: xxx     Code to Test Ratio: 1:x.x

I hope I was able to express the problem 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant