Lean Software Development with Sinatra

The past few weeks have been unbelievably great. One of the reasons why is I attended the WebGeek PH 3rd Year Anniversay in Makati. It may be one of the last ones I’d attend this year. I could travel as far as Japan for the Ruby Conference or attend the next Geekcamp in Singapore. I’ve yet to decide.

Of the things that happened, I am most happy about a paid Sinatra project. It involved consuming a web service and Resque. Thanks to the people who have hired me recently.

When you’re a bootstrapper, you might find using Sinatra is much leaner and faster than using Ruby on Rails. I think I’ve proved that recently.

There aren’t too many Sinatra evangelists out there. If you are using Ruby on Rails and you haven’t tried Sinatra, you should. It is simple and provides all the basic things you’ll need for a functional and very fast web application. I use Sinatra for weekend projects. I am busy on both Sinatra and mobile applications as I have mentioned before somewhere else. It’s my way of keeping my sanity as I work on Ruby on Rails applications.

Organized Sinatra Routes

Now here’s a basic Sinatra template I started. I called it “Simple Sinatra MVC” and it is available on github.com/kathgironpe/simple-sinatra-mvc

It’s a work-in-progress and I want to contribute more changes but I just wanted to provide something basic.

If you know Ruby on Rails, you can create controllers or routes within app/controllers.

At the moment, I use register to make that possible.


module Sinatra
  module Pages
    def self.registered(app)
      app.get '/' do
        readme = './README.md'
        text = File.open(readme) { |f| f.read }
        text = text.force_encoding("UTF-8")
        text = text.match(/Welcome.*$/m)[0] if text['Welcome']
        text = text.match(/(.*)History$/m)[1] if text['History']

        @text = Maruku.new(text).to_html
        haml "pages/index".to_sym
      end
    end
  end
  register Pages
end

Simple Test Frameworks

By working on Sinatra web apps, I learned to appreciate minitest and rack-test. Minitest is Ruby 1.9’s test framework. It’s simple enough. But most of the time I still use and prefer RSpec.

require_relative '../test_helper'

class HomeTest < MiniTest::Unit::TestCase

  include Rack::Test::Methods

  def app() Sinatra::Application end

  def test_hello_world
    get '/'
    assert last_response.ok?
    assert last_response.body.include?('Test String'), "Should include Test String"
  end
end

A Lot of Things Missing

I admit there’s a lot of things missing. When you spend time working on those necessary things missing, it’s no longer lean software development. This is why I wish there were more open source contributors. I think it’s valuable to contribute to open source and do code reading and code reviews.

I will participate in active code review groups or start my own group if and when we have the time. Contact me if you are interested.

But There Are More Ruby on Rails Jobs

People with the employee mindset will say that. Well, so what? I would use Sinatra or anything faster than that like Express.js if I want to. It’s easy for me to say I guess.