-
Notifications
You must be signed in to change notification settings - Fork 22k
Fix third party hook for rails stats
Thor command
#52226
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
Fix third party hook for rails stats
Thor command
#52226
Conversation
38bf814
to
c2b17c4
Compare
f9a8a5a
to
6603a8d
Compare
Instead of having a config setting that requires a booted application, it would probably be better to have a clear API on CodeStatistics: CodeStatistics.add_directory("My Directory", "path/to/dir") |
6603a8d
to
44e7a0c
Compare
I've changed the PR to use |
STATS_DIRECTORIES
in favor of `config.code_statistics.directoriesSTATS_DIRECTORIES
in favor of CodeStatistics.add_directory
25acec7
to
ff2c5e3
Compare
STATS_DIRECTORIES
in favor of CodeStatistics.add_directory
rails stats
Thor command
rails stats
Thor commandrails stats
Thor command
57d61c6
to
0b279d4
Compare
0b279d4
to
1ac3d37
Compare
require "rails/code_statistics_calculator" | ||
require "active_support/core_ext/enumerable" | ||
|
||
class CodeStatistics # :nodoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is nodoc, we can't add a method we expect people to use on it and keep it nodoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets remove the nodoc
and document this class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to document this class should it also be namespaced under Rails::
like most classes in railties/lib/rails
?
Otherwise we'll have a top level constant CodeStatistics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙂
require "rails/code_statistics_calculator" | ||
require "active_support/core_ext/enumerable" | ||
|
||
class CodeStatistics # :nodoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets remove the nodoc
and document this class
`STATS_DIRECTORIES` is used by third parties to add directories to the statistics output. It's a global constant defined in a Rake file, that gets loaded anytime the Rake commands get loaded. For example Rspec Rails adds these in a prepended Rake task: https://github.com/rspec/rspec-rails/blob/8c17b4e5020a4d264e8a79e294c58b5c1ef2b005/lib/rspec/rails/tasks/rspec.rake#L43 Rake tasks only get loaded if no matching Thor task has been found. This means `STATS_DIRECTORIES` is only available when the Rake commands have loaded. As the stats command has now been moved to a Thor task, calling `bin/rails stats` will no longer add directories to `STATS_DIRECTORIES`, as the Rake commands don't get loaded anymore. To remove the dependency on Rake and avoid a global constant we can add an API to add directories: `CodeStatistics.add_directory`. `STATS_DIRECTORIES` is deprecated. `deprecate_constant` couldn't be used here as that doesn't seem to work for the root namespace. Co-authored-by: Earlopain <14981592+Earlopain@users.noreply.github.com>
1ac3d37
to
271467b
Compare
Legacy
STATS_DIRECTORIES
hook for Rake no longer worksSTATS_DIRECTORIES
is used by third parties to add directories to the statistics output. It's a global constant defined in a Rake file, that gets loaded anytime the Rake commands get loaded.For example Rspec Rails adds
spec
directories in a prepended Rake task: https://github.com/rspec/rspec-rails/blob/8c17b4e5020a4d264e8a79e294c58b5c1ef2b005/lib/rspec/rails/tasks/rspec.rake#L43Rake tasks only get loaded if no matching Thor task has been found. This means this constant is only available when the Rake commands have loaded.
New
CodeStatistics.add_directory
for Thor commandAs the stats command has now been moved to a Thor task, calling
bin/rails stats
will no longer add directories toSTATS_DIRECTORIES
, as the Rake commands don't get loaded anymore.To remove the dependency on Rake and avoid a global constant we can add an API to add directories:
CodeStatistics.add_directory
.STATS_DIRECTORIES
is deprecated.deprecate_constant
couldn't be used here as that doesn't seem to work for the root namespace.This was previously proposed/discussed in #49759, but I decided to resubmit it with the recent commit to make
stats
a Thor task.Before
bin/rake stats
adds custom directories (Model specs in this case):bin/rails stats
does not add custom directories (Model specs):After
bin/rake stats
adds directories (Model specs).bin/rails stats
adds directories added in aRaills.application.config.after_initialize
block.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]