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

Register stats directories with Rails::CodeStatistics.register_directory #2081

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ nav_order: 5

*Tomasz Kowalewski*

* Register stats directories with `Rails::CodeStatistics.register_directory` to support `rails stats` in Rails 8.

*Petrik de Heus*

## 3.14.0

* Defer to built-in caching for language environment setup, rather than manually using `actions/cache` in CI.
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ ViewComponent is built by over a hundred members of the community, including:
<img src="https://avatars.githubusercontent.com/nielsslot?s=64" alt="nshki" width="32" />
<img src="https://avatars.githubusercontent.com/nshki?s=64" alt="nshki" width="32" />
<img src="https://avatars.githubusercontent.com/ozydingo?s=64" alt="ozydingo" width="32" />
<img src="https://avatars.githubusercontent.com/p8?s=64" alt="p8" width="32" />
<img src="https://avatars.githubusercontent.com/patrickarnett?s=64" alt="patrickarnett" width="32" />
<img src="https://avatars.githubusercontent.com/rainerborene?s=64" alt="rainerborene" width="32" />
<img src="https://avatars.githubusercontent.com/rdavid1099?s=64" alt="rdavid1099" width="32" />
Expand Down
12 changes: 10 additions & 2 deletions lib/view_component/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ module ViewComponent
class Engine < Rails::Engine # :nodoc:
config.view_component = ViewComponent::Config.current

rake_tasks do
load "view_component/rails/tasks/view_component.rake"
if Rails.version.to_f < 8.0
rake_tasks do
load "view_component/rails/tasks/view_component.rake"
end
else
initializer "view_component.stats_directories" do |app|
require "rails/code_statistics"
dir = ViewComponent::Base.view_component_path
Rails::CodeStatistics.register_directory("ViewComponents", dir)
end
end

initializer "view_component.set_configs" do |app|
Expand Down
20 changes: 11 additions & 9 deletions test/sandbox/test/rake_tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

require "test_helper"

module ViewComponent
class RakeTasksTest < TestCase
def setup
Kernel.silence_warnings do
Sandbox::Application.load_tasks
if Rails.version.to_f < 8.0
module ViewComponent
class RakeTasksTest < TestCase
def setup
Kernel.silence_warnings do
Sandbox::Application.load_tasks
end
end
end

def test_statsetup_task
Rake::Task["view_component:statsetup"].invoke
assert_includes ::STATS_DIRECTORIES, ["ViewComponents", "app/components"]
def test_statsetup_task
Rake::Task["view_component:statsetup"].invoke
assert_includes ::STATS_DIRECTORIES, ["ViewComponents", "app/components"]
end
end
end
end
Loading