开发者

With Ruby + Webrick + Sinatra, where does 'development?' method come from?

Where does the concept of 'development mode' come from when 开发者_如何学Cusing ruby + webrick + sinatra?

require 'sinatra'
require 'sinatra/reloader'

get '/test' do
  development?.to_s
end

When I run the above app by 'ruby test.rb -p 3000' http://localhost:3000/test returns "true" ... but why does it return true? Is development mode a ruby, webrick, rack or sinatra concept? Also, is this functionality documented anywhere in particular in a non-rails specific manner? I'm finding many people reference the concept of development mode, but I've been surprised by how hard it has been to find relevant information ... maybe I'm just not google-ing the right keywords ...


Sinatra's source code (base.rb) shows these 3 definitions:

def development?; environment == :development end
def production?;  environment == :production  end
def test?;        environment == :test        end

So those true/false methods are based on the set environment. Sinatra defaults to run in development mode unless you tell it otherwise (when you start a Sinatra app, you'll see something like

== Sinatra/1.2.6 has taken the stage on 4567 for **development** with backup from WEBrick".

To tell it to run in production, you would do this:

ruby test.rb -p 3000 -e production
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜