Correct registration settings for Sinatra + DataMapper

I wonder how to properly configure configure blocks in Sinatra DRY mode. I want to:

  • When exceptions and errors are not displayed at the factory
  • During development, write queries to DB
  • When testing, use SQLite db in memory.

I installed the following:

configure :production do set :show_exceptions, false set :raise_errors, false end configure :development do DataMapper::Logger.new($stdout, :debug) end configure :test do DataMapper.setup(:default, "sqlite::memory:") end 

But what to put in the configuration block base? Is this the right approach? In addition, I could not find what the correct order of execution of the configuration blocks in Sinatra was.

+4
source share
2 answers

You do not need your production configuration, as this is already the default value. Otherwise, it looks fine. If true for all environments, it is placed in a common configuration block; if it is special for one environment or two, it makes it an additional block. See the Sinatra Readme file for more details.

0
source
 class App < Sinatra::Base configure :development do enable :logging, :dump_errors, :raise_errors disable :show_exceptions DataMapper::Logger.new(STDOUT, :debug, '[DataMapper] ') DataMapper::Model.raise_on_save_failure = true end configure :test do enable :dump_errors, :raise_errors disable :run, :logging, :show_exceptions end ## Log to file # FileUtils.mkdir_p 'log' unless File.exists?('log') # log_file = File.new('log/development.log', 'a') # $stdout.reopen(log_file) # $stderr.reopen(log_file) # $stderr.sync = true # $stdout.sync = true 
0
source

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


All Articles