Karl Oscar Weber

How I spent the last 10 days Fixing an old Ruby Web Framework.

This is not just a technical discussion, but a description of my efforts to find a replacement for rails, and why.

I'm not going to get into details too much, but the popular web framework Ruby on Rails, is open source, really easy to use, and still runs some pretty big startups. The Original creator DHH, which I will refer to in this article as The Dumbass, is still very active with the thing. But he keeps doing Dumbass Shit. Like I'm tired of his shit and I'm not even primarily a rails devloper. I have other things to worry about.

I decided that I didn't want to have any association, not even tangentially, with that dude. So I'm like: "I have to port all this old code I have". I was attached to my code.

I was tired of tangentially associating with the work of a puffy ego shit head that says politics is getting out of hand, and that routinely causes harm.

As Kim Crayton says: Tech is Not Neutral, Nor is it Apolitical. My personal choice in tech and contribution to it won't be either. So I wanted to choose some tech that wasn't associated with a sociopath.

Anyways I set about Porting My code.

I'm not even that good with Ruby. I honestly pretty much suck. That was the problem. I have a mountain of code that I have to improve/maintain plus several personal projects that I'm trying to move forward. I'm committed to Ruby though.

I googled best Ruby Frameworks. I figured that at least some of my code would be portable. I had figured out some difficult record relationships logic in rails for app permissions and I didn't want to abandon that. There are a LOT of Ruby frameworks. like a lot. Some Highlights:

Hanami: A fast and Modern web framework. I really like this one. There are simple patterns and very good documentation to get you started. The organization behind it, dry-rb, is pretty amazing too.

Sinatra: A DSL for quickly creating web applications. This one felt a little too minimal to me. It's also great.

Grape: A framework for creating REST like APIs in Ruby. This one is good too. Most of what I'm making are APIs for iOS and Web apps so this made sense to me.

Camping: A web framework which consistently stays at less than 4kB of code. Written by a mysterious developer that suddenly disappeared in 2009, it's now maintained by the community.

Roda: A routing tree web toolkit, designed for building fast and maintainable web applications in ruby. It's just a bunch of routes. Damn fast.

There were things I liked and didn't like about each one, but in the end I chose to use Camping.

Let's go Camping

The Camping website points to a derelict domain that redirects to a spam site. The Github repo hadn't received an update in 4 years, no real development in 8 years. So this puppy was old. Also it didn't run when I installed it. I was intrigued.

In fact I was unable to compile anything on my computer for like 12 hours because of some Xcode Brew install bug thing. It was tough. After I fixed my computer I tried to fix Camping. I changed a couple of variables, corrected a couple of errors, and then... it worked! This old thing was alive and kicking with it's little 4 kilobytes of Ruby. It felt so good to dive in and learn what was broken and how to fix it.

I was very excited

I mentioned before that I wasn't much good at Ruby. I had never properly learned the language and only used it sometimes to build something small, or to maintain one of the projects that I had inherited. Most of my experience was through Rails. So when everything blew up I decided that I would learn it properly. Fixing Camping was my crash course.

Working through the documentation was a joy. It was very sparse, but clear and simple and to the point. Camping is an MVC micro framework that has everything from routes and middleware, to sessions and databases. ActiveRecord is included. There is literally everything you need in a small package. The best part IS that it's all in a small package.

It's common for a Camping App to fit in a single file without scrolling. It's so concise that you can get a lot done. ActiveRecord gives you instant access to a powerful ORM, migrations included. All this stuff is important for building an app or an API.

How does all this fit into a small package? Well It's because Ruby is amazing. Like I've heard of ruby developers passionate about the language, but HOLY COW it's ridiculous. There's some black magic happening that gives you a lot of power with Ruby.

Strange Magic

Ruby is a purely Object Oriented language. You have classes and objects. But only in Ruby EVERYTHING is an Object, even classes. You can extend or add functionality to ANY Object, even standard library classes. Even classes that you include from the community. And the community of open source code is gigantic, amazing, powerful, useful. You name it. Ruby is STACKED.

I didn't realize that a lot of the magic that I found in rails was simply there because of Ruby. Rails really does put you on Rails, and hides some concepts of Ruby's meta nature that would make understanding what's going on much easier.

Ruby gives you powerful meta programming tools. You're program can modify itself dynamically and write it's own code. This is partly how Camping is so fully featured yet so small. Camping dynamically maps it's routes to your controller methods with a few lines of code that look like a brain teaser. Clever use of regular expressions and code generation make Camping special, and pretty handy. I was immediately productive with it.

Camping is so small you can read the source code in a few minutes and generally understand what it's doing, even for a novice like me. I dived deep into how Ruby Meta Programming works and read the source code like a novel, and consumed the book: The Ruby programming Language. I get it now. Ruby itself is so flexible and dynamic that just about any code can be shared and incorporated into any project. The magic is Ruby itself, and Camping's source code and example is a cheat code to see how to make your own magic.

I was very excited. I feel like I can accomplish just about anything with this little tent.

I'm a Camper now

I reached out to the lead maintainer of Camping and asked if I could contribute. They said YES! So I did! I fixed the tests and now Camping works again. I'm primarily concerned with thoroughly documenting and modernizing the documentation, for my benefit as well as for others, while I build out my own indie projects.

My first project is a User authentication and Oauth Token based middleware system thing. It will be reused for a few projects I'm working on. The best part is that I won't be starting from scratch, I have a lot of old code to work from and port over. Afterwards I think I'll try to move my TOY podcast app a bit farther along. Making a podcast app is a lot harder than it looks.

Try it out!

Download Camping: Add this to your Gemfile to get the latest, actually working version.

gem "camping", git: 'https://github.com/camping/camping' # for installing straight from the repo