123456789_123456789_123456789_123456789_123456789_

Class: Sinatra::Application

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
self, Base, Templates, Helpers, Rack::Utils
Inherits: Sinatra::Base
Defined in: lib/sinatra/base.rb,
lib/sinatra/main.rb

Overview

Execution context for classic style (top-level) applications. All DSL methods executed on main are delegated to this class.

The Application class should not be subclassed, unless you want to inherit all settings, routes, handlers, and error pages from the top-level. Subclassing Sinatra::Base is highly recommended for modular applications.

Constant Summary

Helpers - Included

ETAG_KINDS, MULTIPART_FORM_DATA_REPLACEMENT_TABLE

Base - Inherited

CALLERS_TO_IGNORE, URI_INSTANCE

Class Attribute Summary

Class Method Summary

Base - Inherited

.add_filter

add a filter.

.after

Define an after filter; runs after all requests within the same context as route handlers and may access/modify the request and response.

.before

Define a before filter; runs before all requests within the same context as route handlers and may access/modify the request and response.

.build

Creates a ::Rack::Builder instance with all the middleware set up and the given app as end point.

.call,
.caller_files

Like Kernel#caller but excluding certain magic entries and without line / method information; the resulting array contains filenames only.

.callers_to_ignore,
.condition

Add a route condition.

.configure

Set configuration options for ::Sinatra and/or the app.

.delete,
.disable

Same as calling set <code>:option</code>, false for each of the given options.

.enable

Same as calling set <code>:option</code>, true for each of the given options.

.error

Define a custom error handler.

.extensions

Extension modules registered on this class and all superclasses.

.get

Defining a GET handler also automatically defines a HEAD handler.

.head,
.helpers

Makes the methods defined in the block and in the Modules given in extensions available to the handlers and templates.

.inline_templates=

Load embedded templates from the file; uses the caller's FILE when no file is specified.

.layout

Define the layout template.

.link, .methodoverride=, .methodoverride?,
.middleware

Middleware used in this class and all superclasses.

.mime_type

Lookup or register a mime type in Rack's mime registry.

.mime_types

provides all mime types matching type, including deprecated types:

.new

Create a new instance of the class fronted by its middleware pipeline.

.new!

Alias for Base.new.

.not_found

Sugar for `error(404) { ...

.on_start, .on_stop, .options, .patch, .post,
.prototype

The prototype instance used to process requests.

.put,
.quit!

Stop the self-hosted server if running.

.register

Register an extension.

.reset!

Removes all routes, filters, middleware and extension hooks from the current class (not routes/filters/...

.run!

Run the ::Sinatra app as a self-hosted server using Puma, Falcon, or WEBrick (in that order).

.set

Sets an option to the given value.

.settings

Access settings defined with Base.set.

.start!

Alias for Base.run!.

.stop!

Alias for Base.quit!.

.template

Define a named template.

.unlink,
.use

Use the specified ::Rack middleware.

.agent

Alias for Base.user_agent.

.cleaned_caller

Like Kernel#caller but excluding certain magic entries.

.compile, .compile!,
.define_singleton

Dynamically defines a method on settings.

.force_encoding

Force data to specified encoding.

.generate_method,
.host_name

Condition for matching host name.

.inherited, .invoke_hook,
.provides

Condition for matching mimetypes.

.route, .setup_common_logger, .setup_custom_logger, .setup_default_middleware, .setup_logging, .setup_middleware, .setup_null_logger, .setup_protection, .setup_sessions, .setup_traps,
.start_server

Starts the server by running the ::Rack Handler.

.synchronize,
.user_agent

Condition for matching user agent.

.warn_for_deprecation

used for deprecation warnings.

Instance Attribute Summary

Base - Inherited

Helpers - Included

#bad_request?

whether or not the status is set to 400.

#client_error?

whether or not the status is set to 4xx.

#informational?

whether or not the status is set to 1xx.

#not_found?

whether or not the status is set to 404.

#redirect?

whether or not the status is set to 3xx.

#server_error?

whether or not the status is set to 5xx.

#success?

whether or not the status is set to 2xx.

Instance Method Summary

Base - Inherited

#call

::Rack call interface.

#call!,
#forward

Forward the request to the downstream app -- middleware only.

#halt

Exit the current block, halts any further processing of the request, and returns the specified response.

#pass

Pass control to the next matching route.

#settings

Access settings defined with Base.set.

#dispatch!

Dispatch a request with error handling.

#dump_errors!,
#error_block!

Find an custom error block for the key(s) specified.

#filter!

Run filters defined on the class and all superclasses.

#force_encoding,
#handle_exception!

Error handling during requests.

#invoke

Run the block with 'throw :halt' support and apply result to the response.

#process_route

If the current request matches pattern and conditions, fill params with keys and call the given block.

#route!

Run routes defined on the class and all superclasses.

#route_eval

Run a route block and throw :halt with the result.

#route_missing

No matching route was found or all routes passed.

#static!

Attempt to serve static files from public directory.

Templates - Included

#asciidoc, #builder, #erb,
#find_template

Calls the given block for every possible template file in views, named name.ext, where ext is registered on engine.

#haml, #initialize, #liquid, #markaby, #markdown, #nokogiri, #rabl, #rdoc, #sass, #scss, #slim, #yajl, #compile_block_template, #compile_template, #render,
#render_ruby

logic shared between builder and nokogiri.

Helpers - Included

#attachment

Set the Content-Disposition to "attachment" with the specified filename, instructing the user agents to prompt to save.

#back

Sugar for redirect (example: redirect back).

#body

Set or retrieve the response body.

#cache_control

Specify response freshness policy for HTTP caches (Cache-Control header).

#content_type

Set the content-type of the response body given a media type or file extension.

#error

Halt processing and return the error status provided.

#etag

Set the response entity tag (HTTP 'ETag' header) and halt if conditional GET matches.

#expires

Set the Expires header and Cache-Control/max-age directive.

#headers

Set multiple response headers with Hash.

#last_modified

Set the last modified time of the resource (HTTP 'Last-Modified' header) and halt if conditional GET matches.

#logger

Access shared logger object.

#mime_type

Look up a media type by file extension in Rack's mime registry.

#not_found

Halt processing and return a 404 Not Found.

#redirect

Halt processing and redirect to the URI provided.

#send_file

Use the contents of the file at path as the response body.

#session

Access the underlying ::Rack session.

#status

Set or retrieve the response status code.

#stream

Allows to start sending data to the client even though later parts of the response body have not yet been generated.

#time_for

Generates a Time object from the given value.

#to

Alias for Helpers#uri.

#uri

Generates the absolute URI for a given path in the app.

#url

Alias for Helpers#uri.

#etag_matches?

Helper method checking if a ETag value list includes the current ETag.

#with_params

Constructor Details

This class inherits a constructor from Sinatra::Base

Class Method Details

.register(*extensions, &block)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 2064

def self.register(*extensions, &block) # :nodoc:
  added_methods = extensions.flat_map(&:public_instance_methods)
  Delegator.delegate(*added_methods)
  super(*extensions, &block)
end