ruby: improve configuration for rbenv and rvm

Update documentation
This commit is contained in:
syl20bnr 2015-12-05 21:01:03 -05:00
parent d1ec732cd4
commit 9eb8f86b9a
2 changed files with 46 additions and 30 deletions

View File

@ -69,8 +69,13 @@ example:
'((ruby :variables ruby-version-manager 'rvm)))
#+END_SRC
=Tip:= You can enable different version manager for different projects by using
directory local variables.
When a version manager is enabled it will use the currently activated ruby
except if a =.ruby-version= file exists in which case the ruby version of
this file is used.
=rvm= will also try to look for a =.rvmrc= and =gemfile=, the priority order is
=.rvmrc= then =.ruby-version= then =gemfile=.
Note: Only one version manager at a time can be enabled.
** Test runner
This layer supports both =RSpec= and =ruby-test= test runners (frameworks).

View File

@ -17,59 +17,60 @@
company
evil-matchit
flycheck
rbenv
robe
ruby-test-mode
rspec-mode
ruby-tools
rubocop
rvm
))
(if ruby-enable-enh-ruby-mode
(add-to-list 'ruby-packages 'enh-ruby-mode)
(add-to-list 'ruby-packages 'ruby-mode))
(when ruby-version-manager
(add-to-list 'ruby-packages ruby-version-manager))
(defun ruby/init-chruby ()
(use-package chruby
:if (equal 'chruby 'ruby-version-manager)
:defer t
:init
(progn
(defun spacemacs//enable-chruby ()
"Enable chruby, use .ruby-version if exists."
(when (equal 'chruby 'ruby-version-manager)
(let ((version-file-path (chruby--locate-file ".ruby-version")))
(require 'chruby)
;; try to use the ruby defined in .ruby-version
(if version-file-path
(progn
(chruby-use (chruby--read-version-from-file
version-file-path))
(message "Using ruby version from .ruby-version file."))
(message "Using the currently activated ruby.")))))
(let ((version-file-path (chruby--locate-file ".ruby-version")))
(chruby)
;; try to use the ruby defined in .ruby-version
(if version-file-path
(progn
(chruby-use (chruby--read-version-from-file
version-file-path))
(message (concat "[chruby] Using ruby version "
"from .ruby-version file.")))
(message "[chruby] Using the currently activated ruby."))))
(spacemacs/add-to-hooks 'spacemacs//enable-chruby
'(ruby-mode-hook enh-ruby-mode-hook)))))
(defun ruby/init-rbenv ()
"Initialize RBENV mode"
(use-package rbenv
:if (equal 'rbenv 'ruby-version-manager)
:defer t
:init (global-rbenv-mode)
:config (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
(add-hook hook (lambda () (rbenv-use-corresponding))))))
(defun ruby/init-rvm ()
"Initialize RVM mode"
(use-package rvm
:defer t
:init (rvm-use-default)
:config
:init
(progn
(setq rspec-use-rvm t)
(dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
(add-hook hook
(lambda () (rvm-activate-corresponding-ruby)))))))
(defun spacemacs//enable-rbenv ()
"Enable rbenv, use .ruby-version if exists."
(let ((version-file-path (rbenv--locate-file ".ruby-version")))
(global-rbenv-mode)
;; try to use the ruby defined in .ruby-version
(if version-file-path
(progn
(rbenv-use (rbenv--read-version-from-file
version-file-path))
(message (concat "[rbenv] Using ruby version "
"from .ruby-version file.")))
(message "[rbenv] Using the currently activated ruby."))))
(spacemacs/add-to-hooks 'spacemacs//enable-rbenv
'(ruby-mode-hook enh-ruby-mode-hook)))))
(defun ruby/init-ruby-mode ()
(use-package ruby-mode
@ -232,6 +233,16 @@
"tb" 'ruby-test-run
"tt" 'ruby-test-run-at-point))))
(defun ruby/init-rvm ()
(use-package rvm
:if (equal 'rvm 'ruby-version-manager)
:defer t
:init
(progn
(setq rspec-use-rvm t)
(spacemacs/add-to-hooks 'rvm-activate-corresponding-ruby
'(ruby-mode-hook enh-ruby-mode-hook)))))
(when (configuration-layer/layer-usedp 'auto-completion)
(defun ruby/post-init-company ()
(spacemacs|add-company-hook ruby-mode)