读书人

在Sinatra中灵便地配置Environments

发布时间: 2013-01-05 15:20:39 作者: rapoo

在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???

读书人网 >编程

热点推荐