Sinatra 配置

2023-12-20 15:16 更新

運(yùn)行一次,在啟動(dòng)的時(shí)候,在任何環(huán)境下:

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

只當(dāng)環(huán)境 (RACK_ENV environment 變量) 被設(shè)定為 :production 的時(shí)候運(yùn)行:

configure :production do
  ...
end

當(dāng)環(huán)境被設(shè)定為 :production 或者 :test 的時(shí)候運(yùn)行:

configure :production, :test do
  ...
end

你可以使用 settings 獲得這些配置:

configure do
  set :foo, 'bar'
end

get '/' do
  settings.foo? # => true
  settings.foo  # => 'bar'
  ...
end
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)