akonsu
akonsu

Reputation: 29536

how to set environment type?

I have a Sinatra application that uses sinatra/config_file to parse a YAML configuration file. The file has entries for various environments such as development, test, production.

class MyApp < Sinatra::Base
  register Sinatra::ConfigFile
  config_file 'config.yml'
  @@client = Mysql2::EM::Client.new(
      :host => settings.host,
      :username => settings.username,
      :password => settings.password,
      :database => settings.database
  )

Currently when I run the application, the settings are retrieved from the development section. And the only way that I found to make it use a different one was to set

ENV['RACK_ENV'] = 'production'

in my myapp.rb file.

I do not like editing source, how do I set the environment the proper way?

Upvotes: 0

Views: 146

Answers (1)

Zajn
Zajn

Reputation: 4088

According to the Sinatra documentation, you can run your app in a different environment by using an argument at the command line, as such:

ruby my_app.rb -e [ENVIRONMENT].

Upvotes: 2

Related Questions