I (frontend/javascript developer by trade) wholeheartedly recommend learning the standard unix tools - bash, sed, grep, awk, xargs - for these tasks.<p>While the syntax is daunting at first, and escaping will be an eternal problem, eventually it starts making sense and you'll be able to do <i>anything</i> in seconds. The work in the post becomes trivial:<p><pre><code> mv app/views/foo/**/* app/views/
sed -i 's/\([a-z]*\)foo_\([a-z]*\)path/\1\2path/' app/views/**/*
</code></pre>
or in a more imperative (and probably less efficient) style:<p><pre><code> for file in app/views/foo/**/*; do
sed -i 's/\([a-z]*\)foo_\([a-z]*\)path/\1\2path/' $file
new_path=$(sed 's,foo/,,' <<< $file)
mkdir -p $(dirname $new_path)
mv $file $new_path
done</code></pre>
As the author I thought I'd comment:<p>I wrote this article, because when I was a very new developer, I was learning a lot more Rails than I was Ruby. It had never occurred to me to use Ruby for scripting until I paired with a well rounded Rubyist. With the influx of people learning Rails, I've talked to many people who know much less about Ruby than I did when I was starting out. This isn't mentioned in the article at all, but it was definitely something I thought about when I decided to write it. Honestly, if this helps push one new dev to go out and decided to actually learn some extra Ruby outside of Rails, I'll be happy.<p>I agree 100% about the shell comments. I know enough shell to do my job, but for me it's quicker to write a Ruby script. Not saying it's the most efficient way, but it is a way, and it's more efficient than doing it by hand. As much as I'd love to be a unix shell wizard, I'd rather be improving my Javascript, or learning more Elixir.<p>As for the namespace vs scope: The example was just a way to end up with a scenario where we needed to change some text. Plus, for clarity, if I don't want my controllers or URL namespaced, my routes and files should reflect that, not work around it with a scope unless necessary for some reason(in my opinion). I actually later thought that I should've used the script on a JS project, just to help highlight the fact that this is totally independent of Rails.
I have a scratch folder full of stuff like this written in whatever scripting language is closest at hand, ruby, perl, python, etc. I'd wager most people here would have something similar.<p>I wonder if it would be an interesting project to comb though it all and see if any useful tools could be extracted. Probably not, like the code in this blog most of my one-offs are unashamedly terrible.
Whilst not entirely the point of the article, this could have been accomplished without moving any files by changing the route definition to a scope from a namespace in Rails...
Another awesome tool if you're using emacs is wgrep mode. You get the results of `grep` in a buffer, can edit it like any other text in emacs, and then save writes back to all the original files. Really cool.<p>Emacs macros are wonderful too.
Before i thought mastering regexp were a must to have in a day to day programmer job to quickly modify data with different syntax.<p>Now i am still convinced that regexp are still usefull but you will not get it right for the first try due to syntax corner case.
The best solution in my opinion is to have easy to use parsers including one for your main programming language.<p>Actually i emacs with its macro feature (not elisp) + racket with regexp (didn't mention earlier but having a strong repl for this kind of incremental script is also a must to have) and sometimes parsers.
This probably was the start of writing ruby. I'd recommend you guys watch this video of someone writing bad ruby in contrast. <a href="https://www.livecoding.tv/video/rails-refactoring/" rel="nofollow">https://www.livecoding.tv/video/rails-refactoring/</a>
If these lot spend two minutes to understand that code at the end, I'd not depend them for my code. He's just processed some text, that's all, don't bother reading.
Or use a language with good tooling: <a href="https://godoc.org/golang.org/x/tools/cmd/gorename" rel="nofollow">https://godoc.org/golang.org/x/tools/cmd/gorename</a>