Skip to content

Commit

Permalink
reorganized the tasks so that rewrite:clear deletes all of the rewrit…
Browse files Browse the repository at this point in the history
…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
raganwald committed Dec 29, 2008
1 parent 9a9daf8 commit f5fd016
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
19 changes: 17 additions & 2 deletions tasks/rewrite.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f5fd016

Please sign in to comment.