Fork me on GitHub

vegas

What

Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.

Why

I have a vision of a future where all us developers release gems with simple local web interfaces powered by Sinatra. I see Vegas as a little shove and an easy first step in making this vision come true.

I presented about “Sinatra: The Framework Within” at GoGaRuCo 2009: Check out the full video.

Usage

Currently, vegas contains a single class Vegas::Runner that provides a wrapper for a Sinatra app to easily make it into an executable bin.

Lets say you have a Sinatra app that looks like:

# /my_app.rb
require 'rubygems'
require 'sinatra/base'

class MyApp < Sinatra::Base
  
  get '/' do
    "This is my app"
  end
  
end

You can turn this into a simple binary:

  #!/usr/bin/env ruby
  # /myapp

  require File.expand_path(File.dirname(__FILE__) + 'myapp.rb')
  require 'vegas'

  Vegas::Runner.new(MyApp, 'my_app')

Now if you run ./my_app it should:

  • find an appropriate rack handler (thin. mongrel)
  • find an available port
  • launch the app in a browser
  • put itself in the background
  • write a .pid and a .url file

Running it with -h or --help will print a list of available command line options. You can even add options specific to your app by using a block.

Vegas::Runner.new(AppClass, 'app_name') do |runner, opts, app|
  # runner is the instance of Vegas::Runner
  # opts is an option parser object
  # app is your app class
end

As of version 0.0.3, Vegas::Runner and its daemon-ization is fully compatible with Windows.

Rack Apps

Vegas (> v0.1.0) is not dependent on Sinatra. Vegas works almost exactly the same for general Rack Applications. For example, this will work as expected:

#!/usr/bin/env ruby

require 'vegas'

app = Proc.new {|env| 
  [200, {'Content-Type' => 'text/plain'}, ["This is an app. #{env.inspect}"]]
}

Vegas::Runner.new(app, 'rack_app')

Dependencies

Vegas requires:

  • rack >= 0.1.0

On Windows, there is an additional requirement of the win32-process gem.

Installing

sudo gem install vegas
        

Or directly from github:

sudo gem install quirkey-vegas -s http://gems.github.com
        

Github in thier infinite awesomeness also lets you download the source in multiple formats.

Bugs/Feature Requests

The full and most up to date source is at github:

http://github.com/quirkey/vegas/

You can clone or fork from there to fix or break the code.

I’m happy to take feature requests/bug reports. Just email me (contact below) or message me on github.

License

This code is free to use under the terms of the MIT license.

Contact

Feel free to email me at aaron at quirkey dot com.

Please check out my blog.

If you like or use this library – I don’t want donations – but you can recommend me on workingwithrails.com or hire me to work on your next project.