Is there a utility for setting up the environment on a rack or on a sinatra?

Is there anything in the Sinatra / Rack world similar to the Rails configuration loading scheme that loads one of the config\enviroments\*.rb files depending on Rails.env

I know that I could develop one quite easily, I just wonder if there is anything already in place.

+4
source share
4 answers

It turns out that there is something from Sinatra that provides similar, albeit limited functionality.

See code: https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1120

So you can do this:

 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
source

If you follow the Rails convention for placing a file for each environment in config / environment / environment_name.rb, you can add something like this in your Sinatra application or for Rack in the config.ru file:

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

With some minor changes, you can force other file locations / file combinations to load. Sinatra also customizes blocks.

+5
source

There is one called Sinatra :: ConfigFile, which now lives in Sinatra :: Contrib http://www.sinatrarb.com/contrib/config_file.html

There is a lot of useful material.

+3
source

I adapted my version on monkrb.com (this is also yaml in RoR)

 YAML.load_file(path_of "config/settings.yml")[RACK_ENV] 

eg. http://github.com/codepants/yasumi/blob/master/config/settings.yml

+1
source

Source: https://habr.com/ru/post/1332717/


All Articles