- C
- D
- F
- G
- H
- N
- O
- P
-
- pass,
- post,
- production?,
- prototype,
- put
- R
- S
- T
- U
| CALLERS_TO_IGNORE | = | [ /\/sinatra(\/(base|main|showexceptions))?\.rb$/, # all sinatra code /lib\/tilt.*\.rb$/, # all tilt code /\(.*\)/, # generated code /custom_require\.rb$/, # rubygems require hacks /active_support/, # active_support require hacks ] |
| [RW] | app | |
| [RW] | env | |
| [RW] | request | |
| [RW] | response | |
| [RW] | params | |
| [R] | routes | |
| [R] | before_filters | |
| [R] | after_filters | |
| [R] | templates | |
| [R] | 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 950 950: def new(*args, &bk) 951: builder = Rack::Builder.new 952: builder.use Rack::Session::Cookie if sessions? 953: builder.use Rack::CommonLogger if logging? 954: builder.use Rack::MethodOverride if methodoverride? 955: builder.use ShowExceptions if show_exceptions? 956: middleware.each { |c,a,b| builder.use(c, *a, &b) } 957: 958: builder.run super 959: builder.to_app 960: end
The prototype instance used to process requests.
# File lib/sinatra/base.rb, line 897 897: def register(*extensions, &block) 898: extensions << Module.new(&block) if block_given? 899: @extensions += extensions 900: extensions.each do |extension| 901: extend extension 902: extension.registered(self) if extension.respond_to?(:registered) 903: end 904: end
Run the Sinatra app as a self-hosted server using Thin, Mongrel or WEBrick (in that order)
# File lib/sinatra/base.rb, line 924 924: def run!(options={}) 925: set options 926: handler = detect_rack_handler 927: handler_name = handler.name.gsub(/.*::/, '') 928: puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " + 929: "on #{port} for #{environment} with backup from #{handler_name}" unless handler_name =~/cgi/i 930: handler.run self, :Host => host, :Port => port do |server| 931: trap(:INT) do 932: ## Use thins' hard #stop! if available, otherwise just #stop 933: server.respond_to?(:stop!) ? server.stop! : server.stop 934: puts "\n== Sinatra has ended his set (crowd applauds)" unless handler_name =~/cgi/i 935: end 936: set :running, true 937: end 938: rescue Errno::EADDRINUSE => e 939: puts "== Someone is already performing on port #{port}!" 940: end
Use the specified Rack middleware
Rack call interface.
# File lib/sinatra/base.rb, line 385 385: def call!(env) 386: @env = env 387: @request = Request.new(env) 388: @response = Response.new 389: @params = indifferent_params(@request.params) 390: @template_cache.clear if settings.reload_templates 391: 392: invoke { dispatch! } 393: invoke { error_block!(response.status) } 394: 395: status, header, body = @response.finish 396: 397: # Never produce a body on HEAD requests. Do retain the Content-Length 398: # unless it's "0", in which case we assume it was calculated erroneously 399: # for a manual HEAD response and remove it entirely. 400: if @env['REQUEST_METHOD'] == 'HEAD' 401: body = [] 402: header.delete('Content-Length') if header['Content-Length'] == '0' 403: end 404: 405: [status, header, body] 406: end
Forward the request to the downstream app — middleware only.
# File lib/sinatra/base.rb, line 429 429: def forward 430: fail "downstream app not set" unless @app.respond_to? :call 431: status, headers, body = @app.call(@request.env) 432: @response.status = status 433: @response.body = body 434: @response.headers.merge! headers 435: nil 436: end
Exit the current block, halts any further processing of the request, and returns the specified response.
Alias for settings
Pass control to the next matching route. If there are no more matching routes, Sinatra will return a 404 response.