Skip to content

Instantly share code, notes, and snippets.

@antifuchs
Created August 8, 2013 21:00
Show Gist options
  • Save antifuchs/6188674 to your computer and use it in GitHub Desktop.
Save antifuchs/6188674 to your computer and use it in GitHub Desktop.
;;; Patch inf-ruby to load more code by default:
(require 'inf-ruby)
(setq inf-ruby-console-patterns-alist
'(("*.gemspec" . asf-gem)
("scripts/bin/console" . pay-server)
("Gemfile" . default)))
(defun inf-ruby-console-asf-gem (dir)
"Run IRB console for the gem in DIR.
The main module should be loaded automatically. If DIR contains a
Gemfile, it should use the `gemspec' instruction."
(interactive "D")
(let* ((default-directory dir)
(files-to-load
;; If there are several files under 'lib'
;; (unlikely), load them all.
(let (files)
(dolist (item (directory-files "lib"))
(unless (file-directory-p item)
(setq files (cons item files))))
(mapconcat
(lambda (file)
(concat " -r " (file-name-sans-extension file)))
files
""))))
(if (file-exists-p "Gemfile")
(run-ruby (concat "bundle exec irb" files-to-load) "gem")
(unless (file-exists-p "lib")
(error "The directory must contain a 'lib' subdirectory"))
(run-ruby (concat "irb -I lib" files-to-load)
"gem"))))
(defun inf-ruby-console-pay-server (dir)
"Start pay-server console in DIR."
(interactive "D")
(let ((default-directory dir))
(run-ruby (concat dir "/scripts/bin/console irb"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment