Build Your Own Web Framework to Understand Rails Magic, by Noah Gibbs

Abstract

Rails "magic" comes from Ruby metaprogramming tricks. Each piece of magic makes sense once you see how Ruby lets you do it. If you want to really understand those tricks, then build them. Join me as we build a Ruby web framework, using Rails' same dependencies. By the end you'll understand some very deep Rails metaprogramming tricks. You'll also be able to build your own web framework, whether it works like Rails or not.

Details

This workshop will start from "bundle gem" to create a new gem for the framework, and creating a tiny, trivial test application. Each section will build on the previous to create a reasonably full-featured web framework starting from Rack. This teaches Rack, and also teaches how Rails does several fun tricks.

Each section will feature on-GitHub "starter" code, based on the end state of the previous section. That way attendees can drop in at section boundaries or "reset" their progress if they're having trouble with an earlier section. It also provides easy stopping places for folks wanting to finish up and leave.

The sections, in order, are:

  • Build a framework gem, and a basic Rack application, with basic tests
  • Simple Rack-compatible controllers
  • Automatically load classes without "require"
  • Simple ERB views
  • Simple models (I'll talk about ORMs here but we won't write an ORM in the workshop)
  • Rack middleware (time permitting)

The framework will be usable at the end of each section, and most sections can be detached for individual use in other projects with a bit of work.

Finally, I'll provide a list of resources for continued work -- links about how to build or integrate framework components such as validations, ORMs and non-ERB views. I'll also provide an initial list of places to begin reading the Rails source code to see how Rails does these same things, and a guide to basic Rails-style code organization as your app grows.

Pitch

I've given the same material internally as a workshop at two previous employers -- I think it would be great at RailsConf as well. But basically, I've done this as a professional full-week training and I think an abbreviated version will make a great RailsConf workshop.

I've also done some other relevant work on this topic, but I don't know how to describe it here without identity spoilers.

Speaker Info

Noah is a Ruby Fellow for AppFolio, working on the core Ruby language and related tooling. As a trained massage therapist and hypnotherapist, he uses his powers of evil for good. He intends his children to rule in his stead - obey them as you would him. He also wrote the book "Rebuilding Rails," which is universally worshipped as "pretty good."

Notes

I had originally written a very different pitch, given that I've written a book about this. Then I realized that RailsConf wants anonymized pitches. Um, d'oh! So this is what I came up with instead.

Edit proposal

Submissions

RailsConf 2019 - Accepted [Edit]

Add submission