Class: Sinatra::Application
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
|
|
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
Class Attribute Summary
Base
- Inherited
.development?, .errors, .filters, .on_start_callback, .on_stop_callback, .production?, .public=, .public_dir, .public_dir=, .routes, | |
.running? | Check whether the self-hosted server is running or not. |
.templates, .test?, .suppress_messages? |
Class Method Summary
- .register(*extensions, &block) Internal use only
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 |
.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 |
.delete, | |
.disable | Same as calling |
.enable | Same as calling |
.error | Define a custom error handler. |
.extensions |
|
.get | Defining a |
.head, | |
.helpers | Makes the methods defined in the block and in the Modules given in |
.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 |
|
.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 |
.set | Sets an option to the given value. |
.settings | Access settings defined with |
.start! | Alias for Base.run!. |
.stop! | Alias for Base.quit!. |
.template | Define a named template. |
.unlink, | |
.use | Use the specified |
.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_host_authorization, .setup_logging, .setup_middleware, .setup_null_logger, .setup_protection, .setup_sessions, .setup_traps, | |
.start_server | Starts the server by running the |
.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 |
|
#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 |
#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! |
|
#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 |
#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 |
#session | Access the underlying |
#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