Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sinatra app in a gem

Tags:

ruby

gem

sinatra

I have a Sinatra application I've created and I'd like to package it as a gem-based binary.

I have my gemspec and gem set up to generate a suitable executable that points to the my_sinatra_app.rb (which is executable) but the sinatra server never runs. Any ideas why and how to make it work?

my_sinatra_app executable:

#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
#
# This file was generated by RubyGems.
require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'my_sinatra_app', version
load Gem.bin_path('my_sinatra_app', 'my_sinatra_app', version)
like image 817
JP. Avatar asked Apr 06 '10 09:04

JP.


1 Answers

Found out :D

You need to wrap your Sinatra app in a class like so:

class MySinatraApp < Sinatra::Application
  # Stuff
end

Then in the file that runs the application you can just do MySinatraApp.run! Simple :)

like image 192
JP. Avatar answered Sep 30 '22 15:09

JP.