Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reorganized the tasks so that rewrite:clear deletes all of the rewrit…

…ten .rb files, rewrite:all rewrites all .rr files, and rewrite:prepare now does both. This garbage collects .rb files that are orphaned.
  • Loading branch information...
commit f5fd01653bb4b11222b8f3603cc9af22ad9c1752 1 parent 9a9daf8
@raganwald raganwald authored
Showing with 18 additions and 3 deletions.
  1. +1 −1  README.md
  2. +17 −2 tasks/rewrite.rake
View
2  README.md
@@ -66,7 +66,7 @@ Where the rewrite gem allows you to rewrite specific blocks of code and to treat
* **That was fun, but we hired a new architect who has decided make his mark by criticizing all of our decisions and insists we stop all new development while we migrate it out of our million line project. Are we fuxxored?**
-Your new smartest guy in the room might be fuxxored, but your code is safe. Simply run `rake rewrite:prepare rewritten=.` This does the `prepare` task that rewrites all of your code in place, but instead of placing the resulting `.rb` files in a hierarchy in the `rewritten` folder, it places them all in a hierarchy in the root of your project. Which means, they go right next to the .rr files. You can now remove the rewrite plugin and carry on. Removing the out-dated `.rr` files from the command line shouldn't be a problem for your new smart fellow.
+Your new smartest guy in the room might be fuxxored, but your code is safe. Simply run `rake rewrite:all rewritten=.` This does the `prepare` task that rewrites all of your code in place, but instead of placing the resulting `.rb` files in a hierarchy in the `rewritten` folder, it places them all in a hierarchy in the root of your project. Which means, they go right next to the .rr files. You can now remove the rewrite plugin and carry on. Removing the out-dated `.rr` files from the command line shouldn't be a problem for your new smart fellow.
The summary is that you can experiment with `RewriteRails` as much as you like, but you are not painting yourself into a corner. You can escape to standard Ruby at any time.
View
19 tasks/rewrite.rake
@@ -1,10 +1,25 @@
namespace :rewrite do
- desc "prepare for deployment by rewriting all .rr fils to .rb files"
- task :prepare => :environment do
+ desc "rewrite all .rr files to .rb files"
+ task :all => :environment do
`find #{RAILS_ROOT} -name "*.rr"`.each do |rr_path|
RewriteRails.rewrite_file(rr_path.strip)
end
end
+ desc "clear all cached .rb files"
+ task :clear => :environment do
+ rewritten_folder = File.expand_path(RewriteRails.cache_folder_name())
+ if rewritten_folder != File.expand_path(RAILS_ROOT)
+ `find #{rewritten_folder} -name "*.rb"`.each do |rb_path|
+ File.delete(rb_path.strip)
+ end
+ else
+ raise "You cannot clear cached files if you are rewriting to the rails root: you will delete all .rb files as well"
+ end
+ end
+
+ desc "prepare for deployment by rewriting all .rr files to .rb files"
+ task :prepare => [:clear, :all]
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.