使用ruby + webrick + sinatra时,'开发模式'的概念来自哪里?
require 'sinatra' require 'sinatra/reloader' get '/test' do development?.to_s end当我通过'ruby test.rb -p 3000'运行上面的应用程序时http:// localhost:3000 / test返回“true”...但为什么它返回true? 开发模式是ruby,webrick,rack还是sinatra概念? 此外,特定于非特定于轨道的方式记录此功能吗? 我发现很多人都参考了开发模式的概念,但我一直惊讶于找到相关信息的难度......也许我只是没有谷歌正确的关键词......
Where does the concept of 'development mode' come from when using ruby + webrick + sinatra?
require 'sinatra' require 'sinatra/reloader' get '/test' do development?.to_s endWhen 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的源代码(base.rb)显示了这3个定义:
def development?; environment == :development end def production?; environment == :production end def test?; environment == :test end因此,这些真/假方法基于设置环境。 Sinatra默认在开发模式下运行,除非你另外告诉它(当你启动Sinatra应用程序时,你会看到像
== Sinatra/1.2.6 has taken the stage on 4567 for **development** with backup from WEBrick".
要告诉它在生产中运行,你会这样做:
ruby test.rb -p 3000 -e productionSinatra's source code (base.rb) shows these 3 definitions:
def development?; environment == :development end def production?; environment == :production end def test?; environment == :test endSo 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更多推荐
发布评论