16

What's the proper way to determine the environment? Right now I'm using:

class Main < Sinatra::Base
    get '/' do
        puts self.class.development?
        puts self.class.production?
    end
end

But it doesn't seem right.

pguardiario
  • 53,827
  • 19
  • 119
  • 159

3 Answers3

33

I would use Sinatra::Base.development? or Sinatra::Base.production? since that is where the methods are coming from.

Jim Deville
  • 10,632
  • 1
  • 37
  • 47
23

self.class.development? should actually work. These all work for me on Sinatra 1.3.1:

class Main < Sinatra::Base
  get '/' do
    puts Main.development?
    puts self.class.development?
    puts settings.development?
    puts settings.environment == :development
  end
end
tbuehlmann
  • 9,032
  • 5
  • 27
  • 33
2

puts Sinatra::Application.environment

#=> production (or test, development)

Siwei
  • 19,858
  • 7
  • 75
  • 95