ruby: improve chruby configuration
Look for a .ruby-version file, if it does not exist then use the currently activated ruby. Update documentation.
This commit is contained in:
parent
c5e260f46d
commit
d1ec732cd4
|
@ -60,15 +60,17 @@ specific documentation for details and caveats):
|
|||
#+END_SRC
|
||||
|
||||
** Ruby version management
|
||||
This layer supports the use of [[https://rvm.io/][RVM]], [[https://github.com/sstephenson/rbenv][Rbenv]], and [[https://github.com/postmodern/chruby][Chruby]].
|
||||
To enable it, set the =ruby-version-manager= var in your =~/.spacemacs=:
|
||||
This layer supports [[https://rvm.io/][RVM]], [[https://github.com/sstephenson/rbenv][Rbenv]], and [[https://github.com/postmodern/chruby][Chruby]]. You can choose the default version
|
||||
manager by setting the variable =ruby-version-manager= in your dotfile, for
|
||||
example:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun dotspacemacs-configuration-layers ()
|
||||
'((ruby :variables ruby-version-manager 'rbenv)))
|
||||
'((ruby :variables ruby-version-manager 'rvm)))
|
||||
#+END_SRC
|
||||
|
||||
Possible values are =rbenv=, =rvm= and =chruby=.
|
||||
=Tip:= You can enable different version manager for different projects by using
|
||||
directory local variables.
|
||||
|
||||
** Test runner
|
||||
This layer supports both =RSpec= and =ruby-test= test runners (frameworks).
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
"If non-nil, use `enh-ruby-mode' package instead of the built-in Ruby Mode.")
|
||||
|
||||
(defvar ruby-version-manager nil
|
||||
"If non nil, defines the Ruby version manager (i.e. rbenv, rvm)")
|
||||
"If non nil, defines the Ruby version manager.
|
||||
Possible values are `rbenv', `rvm' or `chruby'.)")
|
||||
|
||||
(defvar ruby-use-ruby-test nil
|
||||
"If non-nil, use `ruby-test-mode' package instead of `rspec-mode'.")
|
||||
|
@ -27,9 +28,6 @@
|
|||
(defvar ruby-test-runner 'ruby-test
|
||||
"Test runner to use. Possible values are `ruby-test' or `rspec'.")
|
||||
|
||||
(defvar chruby-ruby-version nil
|
||||
"If non-nil, sets chruby ruby version, see https://github.com/plexus/chruby.el for more information.")
|
||||
|
||||
;; Command prefixes
|
||||
|
||||
(spacemacs/declare-prefix-for-mode 'ruby-mode "mt" "ruby/test")
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
(setq ruby-packages
|
||||
'(
|
||||
bundler
|
||||
chruby
|
||||
company
|
||||
evil-matchit
|
||||
flycheck
|
||||
|
@ -30,14 +31,25 @@
|
|||
(when ruby-version-manager
|
||||
(add-to-list 'ruby-packages ruby-version-manager))
|
||||
|
||||
(defun ruby/init-chruby()
|
||||
"Initialize Chruby mode"
|
||||
(defun ruby/init-chruby ()
|
||||
(use-package chruby
|
||||
:defer t
|
||||
:init (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook)))
|
||||
(add-hook hook
|
||||
(lambda () (chruby (if chruby-ruby-version 'chruby-ruby-version
|
||||
(message "chruby version not set!!")))))))
|
||||
: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.")))))
|
||||
(spacemacs/add-to-hooks 'spacemacs//enable-chruby
|
||||
'(ruby-mode-hook enh-ruby-mode-hook)))))
|
||||
|
||||
(defun ruby/init-rbenv ()
|
||||
"Initialize RBENV mode"
|
||||
|
|
Loading…
Reference in New Issue