ruby - Sinatra configuring environments on the fly -


i have successfull written little sinatra application , deployed on heroku.

however want run application in development mode on local computer , want have production mode on heroku once push remote repository.

currently can achieve either 1 of thos options. when change config.ru following values:

require 'rubygems' require 'sinatra' require 'sinatra/reloader' require "./calc.rb"  enable :logging set :environment, :development set :port, 4567 

i'm able run locally (on port 4567) via ruby config.ru. when change config.ru this:

require 'rubygems' require 'sinatra' require 'sinatra/reloader' require "./calc.rb"  enable :logging set :environment, :production set :port, 4567 run sinatra::application 

i'm able run on heroku (on port 80).

but can not use same configuration both development , production.

i have like:

ruby config.ru dev development , ruby config.ru production.

additional information:

when try run production config.ru on local machine get:

$ ruby config.ru (eval):2:in `method_missing': undefined method `run' main:object (nomethoderror)         (eval):4:in `__send__'         (eval):4:in `method_missing'         config.ru:10 

c:\>type tmp.ru require 'sinatra' configure(:production){  p "i'm production" } configure(:development){ p "i'mma dev mode" } configure(:sassycustom){ p "i'mma own mode" } exit!  c:\>rackup tmp.ru "i'mma dev mode"  c:\>rackup -e development tmp.ru "i'mma dev mode"  c:\>rackup -e production tmp.ru "i'm production"  c:\>rackup -e sassycustom tmp.ru "i'mma own mode"  c:\>rackup -e notdefined tmp.ru 

if don't specify environment, development used default. can specify environment name want, though 'production' common. if specify environment don't configure, no configuration block match. (it might mistake on part, it's not error caught code.)

note sinatra documentation says setting rack_env environment variable used if available. used not work, time in last few years has been fixed!

if, example, can set environment variable service, can control mode.


Comments