DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Rails-reverse-rename-column
Emacs lisp macro for rails development to reverse the order of the columns in rename_column
Could use this approach to automatically rewrite most of the migration's "down"
(defun rails-reverse-rename-column ()
"In a rails migration, from point to end of buffer, reverse the order of renamed columns"
(interactive)
(save-excursion
(while (re-search-forward "rename_column *\"\\([^\"]*\\)\" *, *\"\\([^\"]*\\)\" *, *\"\\([^\"]*\\)\" *$" nil t)
(replace-match "rename_column \"\\1\", \"\\3\", \"\\2\""))))




