Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use appropriate command invocations for rails tasks. #9

Merged
merged 3 commits into from

2 participants

@joodie
Collaborator

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.

joodie and others added some commits
@joodie joodie 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`.
e8caeed
@joodie joodie Run default webserver with correct invocation. 20206f4
@remvee Allow script to be ran when visiting a file in the project; current w…
…orking directory does not always reflect project root.
a460fdf
@remvee remvee merged commit bab74aa into master
@remvee remvee deleted the rails-scripts branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 16, 2013
  1. @joodie

    Use appropriate command invocations for rails tasks.

    joodie authored
    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`.
  2. @joodie
  3. Allow script to be ran when visiting a file in the project; current w…

    authored
    …orking directory does not always reflect project root.
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 52 deletions.
  1. +2 −2 rails-ruby.el
  2. +31 −39 rails-scripts.el
  3. +3 −11 rails-ws.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 (rails-core:file "script/rails") command))
+ ((file-exists-p (rails-core:file (format "script/%s" command)))
+ (list rails-ruby-command (rails-core:file (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)
-
View
14 rails-ws.el
@@ -115,17 +115,9 @@ using `rails-default-environment'."
(format "-p %s -e %s start"
port
env)))
- ((file-exists-p (rails-core:file "script/rails"))
- (list rails-ruby-command
- (format "script/rails server -p %s -e %s"
- port
- env)))
- (t
- (list rails-ruby-command
- (format "script/server %s -p %s -e %s"
- server-type
- port
- env)))))
+ (t (let ((cmdlist (append (rails-script:find-rails-command "server")
+ (list "-p" port "-e" env))))
+ (list (car cmdlist) (string-join " " (cdr cmdlist)))))))
(defun rails-ws:stop ()
"Stop the WebServer process."
Something went wrong with that request. Please try again.