- C
- D
- E
- F
- G
- H
- N
- O
- P
-
- pass,
- post,
- production?,
- prototype,
- put
- R
- T
- U
| CALLERS_TO_IGNORE | = | [ /\/sinatra(\/(base|main|showexceptions|compat))?\.rb$/, # all sinatra code /\(.*\)/, # generated code /custom_require\.rb$/, # rubygems require hacks /active_support/, # active_support require hacks ] unless self.const_defined?('CALLERS_TO_IGNORE') |
| [RW] | app | |
| [RW] | env | |
| [RW] | request | |
| [RW] | response | |
| [RW] | params | |
| [RW] | routes | |
| [RW] | filters | |
| [RW] | conditions | |
| [RW] | templates | |
| [RW] | middleware | |
| [RW] | errors |
Like Kernel#caller but excluding certain magic entries and without line / method information; the resulting array contains filenames only.
Set configuration options for Sinatra and/or the app. Allows scoping of settings for certain environments.
Defining a `GET` handler also automatically defines a `HEAD` handler.
Makes the methods defined in the block and in the Modules given in `extensions` available to the handlers and templates
Create a new instance of the class fronted by its middleware pipeline. The object is guaranteed to respond to call but may not be an instance of the class new was called on.
# File lib/sinatra/base.rb, line 885 885: def new(*args, &bk) 886: builder = Rack::Builder.new 887: builder.use Rack::Session::Cookie if sessions? && !test? 888: builder.use Rack::CommonLogger if logging? 889: builder.use Rack::MethodOverride if methodoverride? 890: builder.use ShowExceptions if show_exceptions? 891: 892: @middleware.each { |c,a,b| builder.use(c, *a, &b) } 893: builder.run super 894: builder.to_app 895: end
The prototype instance used to process requests.
# File lib/sinatra/base.rb, line 833 833: def register(*extensions, &block) 834: extensions << Module.new(&block) if block_given? 835: @extensions += extensions 836: extensions.each do |extension| 837: extend extension 838: extension.registered(self) if extension.respond_to?(:registered) 839: end 840: end
# File lib/sinatra/base.rb, line 901 901: def reset!(base=superclass) 902: @routes = base.dupe_routes 903: @templates = base.templates.dup 904: @conditions = [] 905: @filters = base.filters.dup 906: @errors = base.errors.dup 907: @middleware = base.middleware.dup 908: @prototype = nil 909: @extensions = [] 910: end
Run the Sinatra app as a self-hosted server using Thin, Mongrel or WEBrick (in that order)
# File lib/sinatra/base.rb, line 860 860: def run!(options={}) 861: set options 862: handler = detect_rack_handler 863: handler_name = handler.name.gsub(/.*::/, '') 864: puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " + 865: "on #{port} for #{environment} with backup from #{handler_name}" unless handler_name =~/cgi/i 866: handler.run self, :Host => host, :Port => port do |server| 867: trap(:INT) do 868: ## Use thins' hard #stop! if available, otherwise just #stop 869: server.respond_to?(:stop!) ? server.stop! : server.stop 870: puts "\n== Sinatra has ended his set (crowd applauds)" unless handler_name =~/cgi/i 871: end 872: end 873: rescue Errno::EADDRINUSE => e 874: puts "== Someone is already performing on port #{port}!" 875: end
Use the specified Rack middleware
Rack call interface.
# File lib/sinatra/base.rb, line 369 369: def call!(env) 370: @env = env 371: @request = Request.new(env) 372: @response = Response.new 373: @params = nil 374: 375: invoke { dispatch! } 376: invoke { error_block!(response.status) } 377: 378: status, header, body = @response.finish 379: 380: # Never produce a body on HEAD requests. Do retain the Content-Length 381: # unless it's "0", in which case we assume it was calculated erroneously 382: # for a manual HEAD response and remove it entirely. 383: if @env['REQUEST_METHOD'] == 'HEAD' 384: body = [] 385: header.delete('Content-Length') if header['Content-Length'] == '0' 386: end 387: 388: [status, header, body] 389: end
Forward the request to the downstream app — middleware only.
# File lib/sinatra/base.rb, line 411 411: def forward 412: fail "downstream app not set" unless @app.respond_to? :call 413: status, headers, body = @app.call(@request.env) 414: @response.status = status 415: @response.body = body 416: @response.headers.merge! headers 417: nil 418: end
Exit the current block, halts any further processing of the request, and returns the specified response.
Access options defined with Base.set.