Commit 3a08e0766ea8ebb4cab0299e902ec5a311042785

add rename-table snippets to migration after rename-model
  
313313 (lambda (val) (rails-refactoring:decamelize (pluralize-string val))))))))
314314
315315 (let ((migration-name (concat "Rename" (pluralize-string from) "To" (pluralize-string to))))
316 (rails-script:generate-migration migration-name)
317 (message "TODO add rename-table statements to migration")
318 (message "TODO add rename association columns to migration")))
316 (rails-refactoring:enqueue-migration-edit migration-name
317 'rails-refactoring:rename-table-migration-edit from to)
318 (rails-script:generate-migration migration-name)))
319319
320320(defun rails-refactoring:rename-table-migration-edit (from to)
321321 "Add rename table code to migration in current buffer."
330330 (re-search-forward "\\bdef self.down")
331331 (insert "\n")
332332 (indent-according-to-mode)
333 (insert (format "rename_table :%s, :%s" to-table from-table))))
333 (insert (format "rename_table :%s, :%s" to-table from-table))
334 (save-buffer)))
335
336
337;; Setup hooks
338
339(defvar rails-refactoring:after-rails-script-jobs nil
340 "Queue of jobs to be ran via
341`rails-script:run-after-stop-hook'. Jobs are ran by
342`rails-refactoring:run-after-rails-script-jobs' and dequeued when
343they return non nil.")
344
345(defun rails-refactoring:run-after-rails-script-jobs ()
346 "Run pending `rails-script:run-after-stop-hook' refactoring
347jobs"
348 (setq rails-refactoring:after-rails-script-jobs
349 (delete-if (lambda (spec)
350 (funcall (car spec) (cadr spec) (cddr spec)))
351 rails-refactoring:after-rails-script-jobs)))
352
353(add-hook 'rails-script:run-after-stop-hook 'rails-refactoring:run-after-rails-script-jobs)
354
355(defmacro rails-refactoring:enqueue-migration-edit (migration function &rest arguments)
356 "Enqueue migration edit to be run when
357`rails-script:generation-migration' is finished and migration
358file is available."
359 (let ((migration-file (gensym)))
360 `(push (cons (lambda (migration args)
361 (let ((,migration-file (rails-core:migration-file migration)))
362 (when ,migration-file
363 (with-current-buffer (find-file-noselect (rails-core:file ,migration-file))
364 (eval (cons ,function args)))
365 t)))
366 (list ,migration ,@arguments))
367 rails-refactoring:after-rails-script-jobs)))
334368
335369
336370;; Tie up in UI