complete-computing-environment/ruby_on_rails.org

83 lines
2.9 KiB
Org Mode

:PROPERTIES:
:ID: cce/ruby_and_rails_in_emacs
:ROAM_ALIASES: "Ruby on Rails"
:END:
#+TITLE: Ruby and Rails in Emacs
#+filetags: :CCE:Emacs:Coding:
#+AUTO_TANGLE: t
#+PROPERTY: header-args :mkdirp yes :results none
#+PROPERTY: header-args:emacs-lisp :tangle ruby.el
#+PROPERTY: header-args:yaml :tangle roles/endpoint/tasks/ruby.yml
#+ARCOLOGY_KEY: cce/ruby
#+ARCOLOGY_ALLOW_CRAWL: t
#+ARROYO_EMACS_MODULE: ruby
#+ARROYO_MODULE_WANTS: cce/evil_mode.org
*Right now this is disabled*: in the future my rails dev projects should "just" ship a =shell.nix= for [[id:c75d20e6-8888-4c5a-ac97-5997e2f1c711][Nix]].
I use Ruby on Rails for prototyping web applications, it's quick and useful and it's easy to not shoot yourself in the foot with it for personal projects. A lot of this is about setting up the Ruby Version Manager, node.js and the YARN package manager for Node.js's development. I think it's kind of funny the way people respond to Rails these days, but it continues to be an incredible tool for rapid prototyping and exploration of simple data driven applications. Of course life is hard when you're hitting the limits of MRI, but if you have a thing that can fit in a sqlite database on your laptop or a heroku hobby dyno, you can't really complain.
I use [[https://github.com/dgutov/robe][Robe]] for ruby development, rather than the [[id:cce/emacs_and_the_language_server_protocol][LSP]]. I additionally install a =pry= frontend for the [[id:cce/emacs][Emacs]] debugger =realgud=, even if I've never used it, as well as =projectile-rails= and =yari=, a viewer of Ruby =ri= documentation.
#+begin_src emacs-lisp
(use-package realgud-pry)
(use-package yari
:config
(evil-set-initial-state 'yari-mode 'motion)
:bind (:map evil-leader--default-map
("y" . yari)))
(use-package robe
:after company
:config
(push 'company-robe company-backends)
:hook
(ruby-mode . robe-mode)
(ruby-mode . ruby-electric-mode))
(use-package projectile-rails
:hook
(ruby-mode . projectile-rails-on)
(web-mode . projectile-rails-on))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(provide 'cce/ruby)
#+end_src
I use a tool called [[https://github.com/nix-community/bundix][Bundix]] which generates a [[id:c75d20e6-8888-4c5a-ac97-5997e2f1c711][Nix]] derivation of a =Gemfile.lock= which can be used in =nix-shell=.
#+ARROYO_HOME_MODULE: hm/ruby.nix
#+ARROYO_SYSTEM_ROLE: endpoint
#+begin_src nix :tangle ~/arroyo-nix/hm/ruby.nix
{ pkgs, ... }:
{
home.packages = [ pkgs.bundix ];
}
#+end_src
Here's a =default.nix= to crib on new projects; shell in to them, run =bundix -m=, then drop in:
#+NAME: rails-default-nix
#+begin_src nix
with (import <nixpkgs> {});
let
gems = bundlerEnv {
name = "drip-demo";
inherit ruby;
gemdir = ./.;
};
in stdenv.mkDerivation {
name = "drip-demo";
buildInputs = [
gems
gems.wrappedRuby
bundler
nodejs
yarn
];
}
#+end_src