2010-12-20 72 views

回答

5

事實證明,有一些來自Sinatra,提供了一個類似的,但有限的功能。

看到代碼: https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1120

所以,你可以這樣做:

class MyApp < Sinatra::Base 
    configure :development, :test do 
    #only executes this code when environment is equal to one of the passed arguments 
    # I'm pretty sure Sinatra sets this based on ENV['RACK_ENV'] 
    end 
end 
5

如果您按照Rails慣例爲config/environments/environment_name.rb中的每個環境添加一個文件,可以在您的Sinatra應用程序或Rack.ru文件中放入Rack:

Dir.glob(File.dirname(__FILE__) + "/config/environments/#{settings.environment}.rb", &method(:require)) 

通過一些小的修改,您可以使其加載其他文件位置/組合。 Sinatra的配置塊也同樣適用。

+0

謝謝,這就是我最終做的事情......除非我讓它失敗,如果env文件不存在:'require「config /#{settings.environment}」' – 2010-12-20 03:54:40

相關問題