Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use appropriate command invocations for rails tasks.

Standardize calls to generate, console, destroy etc to use the first
version found of `script/$command`, `script/rails $command` or `rails
$command`.

This means those commands now work again in Rails 3+ and with RVM if
you use `rvm.el` with `rvm-activate-corresponding-ruby`.
  • Loading branch information...
commit e8caeed95ef55d9f9bf0b37cbd7307d8e6eb94a2 1 parent ecbad63
@joodie joodie authored
Showing with 33 additions and 41 deletions.
  1. +2 −2 rails-ruby.el
  2. +31 −39 rails-scripts.el
View
4 rails-ruby.el
@@ -97,10 +97,10 @@ See the variable `align-rules-list' for more details.")
(defun run-ruby-in-buffer (buf script &rest params)
"Run CMD as a ruby process in BUF if BUF does not exist."
- (message "run-ruby-in-buffer %s" params)
(let ((abuf (concat "*" buf "*")))
(when (not (comint-check-proc abuf))
- (set-buffer (apply #'make-comint buf rails-ruby-command nil script params)))
+ (let ((cmdlist (append (rails-script:find-rails-command script) params)))
+ (set-buffer (apply #'make-comint buf (car cmdlist) nil (cdr cmdlist)))))
(pop-to-buffer abuf)
(when (fboundp 'inf-ruby-mode)
(inf-ruby-mode)
View
70 rails-scripts.el
@@ -111,12 +111,12 @@ For example -c to remove files from svn.")
(let ((current (current-buffer))
(buf (get-buffer rails-script:buffer-name)))
(if buf
- (if (buffer-visible-p rails-script:buffer-name)
- (delete-windows-on buf)
- (progn
- (pop-to-buffer rails-script:buffer-name t t)
- (pop-to-buffer current t t)
- (run-hooks 'rails-script:show-buffer-hook)))
+ (if (buffer-visible-p rails-script:buffer-name)
+ (delete-windows-on buf)
+ (progn
+ (pop-to-buffer rails-script:buffer-name t t)
+ (pop-to-buffer current t t)
+ (run-hooks 'rails-script:show-buffer-hook)))
(message "No output window found. Try running a script or a rake task before."))))
(defun rails-script:setup-output-buffer ()
@@ -146,7 +146,7 @@ For example -c to remove files from svn.")
(interactive)
(let ((proc (rails-script:running-p)))
(if proc
- (delete-process proc))))
+ (delete-process proc))))
(defun rails-script:sentinel-proc (proc msg)
(let* ((name rails-script:running-script-name)
@@ -190,25 +190,30 @@ BUFFER-MAJOR-MODE and process-sentinel SENTINEL."
(set-process-coding-system proc 'utf-8-dos 'utf-8-dos)
(set-process-sentinel proc 'rails-script:sentinel-proc)
(set-process-filter proc 'ansi-color-insertion-filter)
- (setq rails-script:running-script-name (concat command
- " "
- (strings-join " " parameters)))
- (setq rails-ui:mode-line-script-name (or mode-line-string
+ (setq rails-script:running-script-name
+ (strings-join " " (cons command parameters)))
+ (setq rails-ui:mode-line-script-name (or mode-line-string
command))
(message "Starting %s." rails-script:running-script-name))))))
+(defun rails-script:find-rails-command (command)
+ "Find first of 'script/rails command', 'script/command' or 'rails command' as a list of program & args"
+ (cond ((file-exists-p (rails-core:file "script/rails"))
+ (list rails-ruby-command "script/rails" command))
+ ((file-exists-p (rails-core:file (format "script/%s" command)))
+ (list rails-ruby-command (format "script/%s" command)))
+ (t (list "rails" command))))
+
+(defun rails-script:run-rails-command (command &rest parameters)
+ (let ((cmdlist (append (rails-script:find-rails-command command) parameters)))
+ (rails-script:run (car cmdlist) (cdr cmdlist))))
+
;;;;;;;;;; Destroy stuff ;;;;;;;;;;
(defun rails-script:run-destroy (what &rest parameters)
"Run the destroy script using WHAT and PARAMETERS."
- (if (file-exists-p (rails-core:file "script/rails"))
- (setq script-command "script/rails destroy %s")
- (setq script-command "script/destroy %s"))
-
- (rails-script:run rails-ruby-command
- (append (list (format script-command what))
- parameters
- rails-script:destroy-params-list)))
+ (apply #'rails-script:run-rails-command "destroy" what
+ (append parameters rails-script:destroy-params-list)))
(defun rails-script:destroy (what)
"Run destroy WHAT"
@@ -249,14 +254,8 @@ BUFFER-MAJOR-MODE and process-sentinel SENTINEL."
(defun rails-script:run-generate (what &rest parameters)
"Run the generate script using WHAT and PARAMETERS."
- (if (file-exists-p (rails-core:file "script/rails"))
- (setq script-command "script/rails generate %s")
- (setq script-command "script/generate %s"))
-
- (rails-script:run rails-ruby-command
- (append (list (format script-command what))
- parameters
- rails-script:generate-params-list)))
+ (apply #'rails-script:run-rails-command "generate" what
+ (append parameters rails-script:generate-params-list)))
(defun rails-script:generate (what)
"Run generate WHAT"
@@ -327,13 +326,7 @@ BUFFER-MAJOR-MODE and process-sentinel SENTINEL."
(rails-project:with-root
(root)
(let ((buffer-name (format "rails-%s-%s" (rails-project:name) name)))
- (if (file-exists-p (rails-core:file "script/rails"))
- (apply #'run-ruby-in-buffer buffer-name
- (rails-core:file "script/rails")
- (cons script params))
- (apply #'run-ruby-in-buffer buffer-name
- (rails-core:file (format "script/%s" script))
- params))
+ (apply #'run-ruby-in-buffer buffer-name script params)
(setq ruby-buffer buffer-name))
(rails-minor-mode t)))
@@ -344,11 +337,11 @@ BUFFER-MAJOR-MODE and process-sentinel SENTINEL."
(read-buffer "Environment: " rails-default-environment))))
(let* ((environment (or environment rails-default-environment))
(name (format "console at (%s)" environment))
- (buffer (get-buffer (format "*rails-%s-%s*" (rails-project:name) name))))
+ (buffer (get-buffer (format "*rails-%s-%s*" (rails-project:name) name))))
(if buffer
- (progn
- (when (fboundp 'inf-ruby-mode) (setq inf-ruby-buffer buffer))
- (switch-to-buffer-other-window buffer))
+ (progn
+ (when (fboundp 'inf-ruby-mode) (setq inf-ruby-buffer buffer))
+ (switch-to-buffer-other-window buffer))
(rails-script:run-interactive name
"console"
environment))))
@@ -359,4 +352,3 @@ BUFFER-MAJOR-MODE and process-sentinel SENTINEL."
(rails-script:run-interactive "breakpointer" "breakpointer"))
(provide 'rails-scripts)
-
Please sign in to comment.
Something went wrong with that request. Please try again.