Sinatra 配置
2023-12-20 15:16 更新
运行一次,在启动的时候,在任何环境下:
configure do
# setting one option
set :option, 'value'
# setting multiple options
set :a => 1, :b => 2
# same as `set :option, true`
enable :option
# same as `set :option, false`
disable :option
# you can also have dynamic settings with blocks
set(:css_dir) { File.join(views, 'css') }
end
只当环境 (RACK_ENV environment 变量) 被设定为 :production 的时候运行:
configure :production do
...
end
当环境被设定为 :production 或者 :test 的时候运行:
configure :production, :test do
...
end
你可以使用 settings 获得这些配置:
configure do
set :foo, 'bar'
end
get '/' do
settings.foo? # => true
settings.foo # => 'bar'
...
end
以上内容是否对您有帮助:
更多建议: