1 ;;; rails-rake.el --- emacs-rails integraions with rake tasks.
3 ;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
5 ;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>,
7 ;; Keywords: ruby rails languages oop
8 ;; $URL: svn+ssh://rubyforge/var/svn/emacs-rails/trunk/rails-scripts.el $
9 ;; $Id: rails-scripts.el 117 2007-03-25 23:37:37Z dimaexe $
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License
15 ;; as published by the Free Software Foundation; either version 2
16 ;; of the License, or (at your option) any later version.
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program; if not, write to the Free Software
25 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 (require 'rails-scripts
))
30 (defvar rails-rake
:history
(list))
32 (defvar rails-rake
:tasks-regexp
"^rake \\([^ ]*\\).*# \\(.*\\)"
33 "Regexp to match tasks list in `rake --tasks` output.")
35 (defun rails-rake:create-tasks-cache
(file-name)
36 "Create a cache file from rake --tasks output."
37 (let ((tasks (loop for str in
(split-string (rails-cmd-proxy:shell-command-to-string
"rake --tasks") "\n")
38 for task
= (when (string-not-empty str
)
39 (string=~ rails-rake
:tasks-regexp str $
1))
40 when task collect task
)))
41 (write-string-to-file file-name
(prin1-to-string tasks
))
44 (defun rails-rake:list-of-tasks
()
45 "Return all available tasks and create tasks cache file."
46 (rails-project:in-root
47 (let* ((cache-file (rails-core:file
"tmp/.tasks-cache")))
48 (if (file-exists-p cache-file
)
49 (read-from-file cache-file
)
50 (rails-rake:create-tasks-cache cache-file
)))))
52 (defun rails-rake:list-of-tasks-without-tests
()
53 "Return available tasks without test actions."
55 (tasks (rails-rake:list-of-tasks
))
58 #'(lambda (it) (if (string=~
"^test\\($\\|:\\)" it t
) nil it
))
59 (rails-rake:list-of-tasks
))
63 (defun rails-rake:task
(task &optional major-mode
)
64 "Run a Rake task in RAILS_ROOT with MAJOR-MODE."
65 (interactive (rails-completing-read "What task run" (rails-rake:list-of-tasks-without-tests
)
66 'rails-rake
:history nil
))
68 (rails-script:run
"rake" (list task
) major-mode
)))
70 (defun rails-rake:migrate
(&optional version
)
71 "Run the db:migrate task"
77 (integer (format " VERSION=%.3i" version
))
78 (string (format " VERSION=%s" version
))))))
80 (defun rails-rake:migrate-to-version
(version)
81 "Run migrate with VERSION."
82 (interactive (rails-completing-read "Version of migration"
83 (rails-core:migration-versions t
)
87 (rails-rake:migrate version
)))
89 (defun rails-rake:migrate-to-prev-version
()
90 "Migrate to a previous version."
92 (let ((versions (rails-core:migration-versions t
)))
94 (when (< 2 (length versions
))