简体   繁体   English

使用 Ruby + Webrick + Sinatra,“开发”在哪里? 方法从何而来?

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

Where does the concept of 'development mode' come from when using ruby + webrick + sinatra?使用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?当我通过'ruby test.rb -p 3000' http://localhost:3000/test运行上述应用程序时返回“true”......但为什么它返回true? Is development mode a ruby, webrick, rack or sinatra concept?开发模式是ruby、webrick、rack还是sinatra概念? Also, is this functionality documented anywhere in particular in a non-rails specific manner?此外,此功能是否以非特定于 Rails 的方式记录在任何地方? 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: Sinatra 的源代码 (base.rb)显示了这 3 个定义:

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 默认在开发模式下运行,除非您另有说明(当您启动 Sinatra 应用程序时,您会看到类似

== 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM