I also struggled with this. Here is what I found along the way.
Do you need to be “inside” a class that inherits from Sinatra :: Base (for example, Sinatra :: Application, which inherits from Base) in order to use the development? method development? which is defined in base.rb.
In the classic Sinatra application, you already encode the “inside” class that inherits from Sinatra :: Base. development? will work "anywhere".
In the modular development? sinatra development? will only work in subclasses of Sinatra :: Base, for example:
require 'sinatra/base'
So you can use the ApplicationController class, which inherits from Sinatra :: Base and inside here, for development? . The same goes for subclasses that inherit from your ApplicationController class:
class UserController < ApplicationController require 'dotenv' if development? ... end
For the modular Sinatra in the text of the code (main: Object) to “outside” the Sinatra :: Base subclasses, you need to follow the Arup instructions :
if Sinatra::Base.environment == :development require 'awesome_print' require 'dotenv' Dotenv.load ... end
source share