开发者

Sinatra app in a gem

开发者 https://www.devze.com 2022-12-26 00:34 出处:网络
I have a Sinatra application I\'v开发者_StackOverflowe created and I\'d like to package it as a gem-based binary.

I have a Sinatra application I'v开发者_StackOverflowe 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)


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消