forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, we use both Thor and Rake for `bin/rails` commands. We eventually want to get all the built-ins task promoted to Thor Commands. This migrates the `stats` task to Thor.
- Loading branch information
Showing
4 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
# While global constants are bad, many 3rd party tools depend on this one (e.g | ||
# rspec-rails & cucumber-rails). So a deprecation warning is needed if we want | ||
# to remove it. | ||
STATS_DIRECTORIES ||= [ | ||
%w(Controllers app/controllers), | ||
%w(Helpers app/helpers), | ||
%w(Jobs app/jobs), | ||
%w(Models app/models), | ||
%w(Mailers app/mailers), | ||
%w(Mailboxes app/mailboxes), | ||
%w(Channels app/channels), | ||
%w(Views app/views), | ||
%w(JavaScripts app/assets/javascripts), | ||
%w(Stylesheets app/assets/stylesheets), | ||
%w(JavaScript app/javascript), | ||
%w(Libraries lib/), | ||
%w(APIs app/apis), | ||
%w(Controller\ tests test/controllers), | ||
%w(Helper\ tests test/helpers), | ||
%w(Job\ tests test/jobs), | ||
%w(Model\ tests test/models), | ||
%w(Mailer\ tests test/mailers), | ||
%w(Mailbox\ tests test/mailboxes), | ||
%w(Channel\ tests test/channels), | ||
%w(Integration\ tests test/integration), | ||
%w(System\ tests test/system), | ||
] | ||
|
||
module Rails | ||
module Command | ||
class StatsCommand < Base # :nodoc: | ||
desc "stats", "Report code statistics (KLOCs, etc) from the application or engine" | ||
def perform | ||
require "rails/code_statistics" | ||
|
||
stat_directories = STATS_DIRECTORIES.collect do |name, dir| | ||
[name, Rails::Command.application_root.join(dir)] | ||
end.select { |name, dir| File.directory?(dir) } | ||
|
||
CodeStatistics.new(*stat_directories).to_s | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "isolation/abstract_unit" | ||
require "rails/command" | ||
|
||
class Rails::Command::StatsTest < ActiveSupport::TestCase | ||
include ActiveSupport::Testing::Isolation | ||
setup :build_app | ||
teardown :teardown_app | ||
|
||
test "`bin/rails stats` handles non-existing directories added by third parties" do | ||
app_file "config/initializers/custom.rb", <<~CODE | ||
require "rails/code_statistics" | ||
::STATS_DIRECTORIES << ["Non\ Existing", "app/non_existing"] | ||
CODE | ||
|
||
assert rails "stats" | ||
end | ||
end |