在Sinatra中灵活地配置Environments
configure :development do DataMapper.setup(:default, "postgres://localhost/test") DataMapper.finalize.auto_upgrade! end configure :test do DataMapper.setup(:default, "sqlite::memory:") end configure :production do load_postgres_on_cloudfoundry DataMapper.finalize.auto_upgrade! end?greeting: Welcome to my file configurable application
require "sinatra"require "sinatra/config_file"config_file 'path/to/config.yml'get '/' do @greeting = settings.greeting haml :indexend# The rest of your classic application code goes here...
require "sinatra/base"require "sinatra/config_file"class MyApp < Sinatra::Base register Sinatra::ConfigFile config_file 'path/to/config.yml' get '/' do @greeting = settings.greeting haml :index end # The rest of your modular application code goes here...end?上面的例子是最简单的用法,下面再说明一下如何针对不同的环境分别进行配置:
development: foo: development bar: bartest: foo: test bar: barproduction: foo: production bar: bar
foo: development: development test: test production: productionbar: bar
set :environments, %w{development test production staging}
参考文档:
? ? 1.http://www.sinatrarb.com/contrib/config_file.html???