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
Use Thor for built-in tmp task #47698
base: main
Are you sure you want to change the base?
Conversation
ff8d107
to
119c08c
Compare
e4eae66
to
80612bd
Compare
80612bd
to
7964f65
Compare
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.
As
tmp
directories are sometimes hidden by editors, I've usedtemp
instead.
I don't think changing the code to suit the editor is the right approach.
Which editor are you seeing this problem in? Would it possible to add a dot file in the command's directory (like a .keep
file) to force the editor to recognize the directory?
Rails::Command.invoke "tmp:storage:clear" | ||
end | ||
|
||
# desc :create, "Create tmp directories for cache, sockets, and pids" |
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.
I think we can uncomment this. It's not commented out for the current Rake task.
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.
Done.
module Temp | ||
class CacheCommand < Base # :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.
Unfortunately, putting this module in railties/lib/rails/commands/temp/temp_command.rb
means lookup
won't find these commands (because namespaces_to_paths
won't return the right path):
$ bin/rails tmp:screenshots:clear
Unrecognized command "tmp:screenshots:clear" (Rails::Command::UnrecognizedCommandError)
Did you mean? tmp:sockets:clear
$ bin/rails tmp:sockets:clear
Unrecognized command "tmp:sockets:clear" (Rails::Command::UnrecognizedCommandError)
Did you mean? tmp:cache:clear
$ bin/rails tmp:cache:clear
Unrecognized command "tmp:cache:clear" (Rails::Command::UnrecognizedCommandError)
Did you mean? tmp:clear
(But "Did you mean?" can subsequently suggest them because it uses printing_commands
.)
So each command needs to go into a dedicated subdirectory.
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.
I've extracted these to separate files.
railties/test/commands/temp_test.rb
Outdated
FileUtils.mkdir_p("tmp/cache") | ||
FileUtils.touch("tmp/cache/cache_file") | ||
|
||
FileUtils.mkdir_p("tmp/sockets") | ||
FileUtils.touch("tmp/sockets/socket_file") | ||
|
||
FileUtils.mkdir_p("tmp/screenshots") | ||
FileUtils.touch("tmp/screenshots/fail.png") | ||
|
||
FileUtils.mkdir_p("tmp/storage/6h/np") | ||
FileUtils.touch("tmp/storage/6h/np/6hnp81jvgt42pcfqtlpoy8qshfb0") |
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.
We can use the app_file
helper for each of these.
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.
Nice. I've made the change.
railties/test/commands/temp_test.rb
Outdated
assert_not File.exist?("tmp/cache/cache_file") | ||
assert_not File.exist?("tmp/sockets/socket_file") | ||
assert_not File.exist?("tmp/screenshots/fail.png") | ||
assert_not File.exist?("tmp/storage/6h/np/6hnp81jvgt42pcfqtlpoy8qshfb0") |
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.
It might be worth adding a private assert_file
helper for these that also incorporates app_path
calls. Then we can drop the Dir.chdir
block.
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.
I've added an assert_dir_cleared
that checks the content of the directory.
To make sure we don't delete the directory, this assertion also fails if the directory no longer exists.
railties/test/commands/temp_test.rb
Outdated
rails "tmp:create" | ||
assert Dir.exist?("tmp/cache") | ||
assert Dir.exist?("tmp/sockets") | ||
assert Dir.exist?("tmp/pids") | ||
assert Dir.exist?("tmp/cache/assets") |
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.
I think it would be good to call FileUtils.rm_rf(tmp_dirs)
before rails "tmp:create"
. That way we can be sure we are actually testing creation.
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.
Done.
I'm using Neovim with NerdTree. |
714140b
to
800f8da
Compare
4bf9d76
to
b22a6a7
Compare
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 `tmp` task to Thor. Co-authored-by: Juan Vásquez <javasgon@gmail.com> Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
b22a6a7
to
d2c075e
Compare
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 thetmp
task to Thor.As
tmp
directories are sometimes hidden by editors, I've usedtemp
instead.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]