module Webmachine
Webmachine
is a toolkit for making well-behaved HTTP
applications. It is based on the Erlang library of the same name.
Constants
- CHARSET
Charset string
- COLON
A colon
- CONNECT_METHOD
- CONTENT_ENCODING
HTTP
Content-Encoding- CONTENT_LENGTH
HTTP
Content-Length- CONTENT_TYPE
HTTP
Content-Type- CRLF
Universal
HTTP
delimiter- Configuration
A simple configuration container for items that are used across multiple web server adapters. Typically set using {Webmachine::configure}. If not set by your application, the defaults will be filled in when {Webmachine::run} is called. @attr [String] ip the interface to bind to, defaults to “0.0.0.0”
(all interfaces)
@attr [Integer] port the port to bind to, defaults to 8080 @attr [Symbol] adapter the adapter to use, defaults to :WEBrick @attr [Hash] adapter_options adapter-specific options, defaults to {}
- DASH
A dash
- DATE
HTTP
Date- DELETE_METHOD
- GET_METHOD
- HEAD_METHOD
- HOST
Host string
- HTTP
http string
- IDENTITY
identity Encoding
- LOCATION
HTTP
Location- MATCHES_ALL
- OPTIONS_METHOD
- POST_METHOD
- PUT_METHOD
- SERVER
- SERVER_STRING
String for use in “Server”
HTTP
response header, which includes the {VERSION}.- SLASH
A Slash
- SPLIT_COMMA
Comma split match
- STANDARD_HTTP_METHODS
- STAR
Star Character
- TEXT_HTML
Default Content-Type
- TRACE_METHOD
- TRANSFER_ENCODING
HTTP
Transfer-Encoding- UNDERSCORE
A underscore
- VERSION
Library version
Public Class Methods
@return [Application] the default global Application
# File lib/webmachine/application.rb, line 106 def self.application @application ||= Application.new end
@return [Configuration] the current configuration @see Application#configuration
# File lib/webmachine/configuration.rb, line 30 def self.configuration application.configuration end
Sets the current configuration @param [Configuration] configuration the new config @see Application#configuration=
# File lib/webmachine/configuration.rb, line 37 def self.configuration=(configuration) application.configuration = configuration end
Yields the current configuration to the passed block. @yield [config] a block that will modify the configuration @yieldparam [Configuration] config the adapter configuration @return self @see Application#configure
# File lib/webmachine/configuration.rb, line 23 def self.configure(&block) application.configure(&block) self end
Renders a standard error message body for the response. The standard messages are defined in localization files. @param [Integer] code the response status code @param [Request] req the request object @param [Response] req the response object @param [Hash] options keys to override the defaults when rendering
the response body
# File lib/webmachine/errors.rb, line 17 def self.render_error(code, req, res, options = {}) res.code = code unless res.body title, message = t(["errors.#{code}.title", "errors.#{code}.message"], {method: req.method, error: res.error}.merge(options)) res.body = t('errors.standard_body', {title: title, message: message, version: Webmachine::SERVER_STRING}.merge(options)) res.headers[CONTENT_TYPE] = TEXT_HTML end ensure_content_length(res) ensure_date_header(res) end
Evaluates the passed block in the context of {Webmachine::Dispatcher} for use in adding a number of routes at once. @return [Webmachine] self @see Webmachine::Dispatcher#add_route
# File lib/webmachine/dispatcher.rb, line 95 def self.routes(&block) application.routes(&block) self end
Starts Webmachine’s default global Application
serving requests
# File lib/webmachine.rb, line 24 def self.run application.run end