Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get sinatra environment from within instance method

Tags:

ruby

sinatra

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.

like image 538
pguardiario Avatar asked Nov 19 '11 05:11

pguardiario


2 Answers

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

like image 180
Jim Deville Avatar answered Nov 11 '22 07:11

Jim Deville


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
like image 27
tbuehlmann Avatar answered Nov 11 '22 09:11

tbuehlmann