Module: Webmachine

Extended by:
Translation
Defined in:
lib/webmachine.rb,
lib/webmachine/trace.rb,
lib/webmachine/etags.rb,
lib/webmachine/errors.rb,
lib/webmachine/events.rb,
lib/webmachine/cookie.rb,
lib/webmachine/headers.rb,
lib/webmachine/version.rb,
lib/webmachine/request.rb,
lib/webmachine/adapter.rb,
lib/webmachine/decision.rb,
lib/webmachine/response.rb,
lib/webmachine/resource.rb,
lib/webmachine/adapters.rb,
lib/webmachine/trace/fsm.rb,
lib/webmachine/streaming.rb,
lib/webmachine/media_type.rb,
lib/webmachine/dispatcher.rb,
lib/webmachine/translation.rb,
lib/webmachine/application.rb,
lib/webmachine/decision/fsm.rb,
lib/webmachine/chunked_body.rb,
lib/webmachine/adapters/reel.rb,
lib/webmachine/adapters/rack.rb,
lib/webmachine/configuration.rb,
lib/webmachine/decision/flow.rb,
lib/webmachine/quoted_string.rb,
lib/webmachine/trace/listener.rb,
lib/webmachine/decision/conneg.rb,
lib/webmachine/decision/falsey.rb,
lib/webmachine/decision/helpers.rb,
lib/webmachine/adapters/mongrel.rb,
lib/webmachine/resource/tracing.rb,
lib/webmachine/adapters/webrick.rb,
lib/webmachine/dispatcher/route.rb,
lib/webmachine/adapters/hatetepe.rb,
lib/webmachine/streaming/encoder.rb,
lib/webmachine/resource/encodings.rb,
lib/webmachine/resource/callbacks.rb,
lib/webmachine/trace/resource_proxy.rb,
lib/webmachine/resource/entity_tags.rb,
lib/webmachine/trace/trace_resource.rb,
lib/webmachine/streaming/io_encoder.rb,
lib/webmachine/streaming/fiber_encoder.rb,
lib/webmachine/resource/authentication.rb,
lib/webmachine/trace/pstore_trace_store.rb,
lib/webmachine/events/instrumented_event.rb,
lib/webmachine/streaming/callable_encoder.rb,
lib/webmachine/adapters/lazy_request_body.rb,
lib/webmachine/streaming/enumerable_encoder.rb

Overview

Webmachine is a toolkit for making well-behaved HTTP applications. It is based on the Erlang library of the same name.

Defined Under Namespace

Modules: Adapters, Decision, Events, QuotedString, Streaming, Trace, Translation Classes: Adapter, Application, ChunkedBody, Configuration, Cookie, Dispatcher, ETag, Error, Headers, InvalidResource, MalformedRequest, MediaType, Request, Resource, Response, WeakETag

Constant Summary

VERSION =

Library version

"1.2.2"
SERVER_STRING =

String for use in “Server” HTTP response header, which includes the VERSION.

"Webmachine-Ruby/#{VERSION}"

Class Method Summary (collapse)

Methods included from Translation

t

Class Method Details

+ (Application) application

Returns the default global Application

Returns:



106
107
108
# File 'lib/webmachine/application.rb', line 106

def self.application
  @application ||= Application.new
end

+ (Configuration) configuration

Returns the current configuration

Returns:

See Also:



30
31
32
# File 'lib/webmachine/configuration.rb', line 30

def self.configuration
  application.configuration
end

+ (Object) configuration=(configuration)

Sets the current configuration

Parameters:

See Also:



37
38
39
# File 'lib/webmachine/configuration.rb', line 37

def self.configuration=(configuration)
  application.configuration = configuration
end

+ (Object) configure {|config| ... }

Yields the current configuration to the passed block.

Yields:

  • (config)

    a block that will modify the configuration

Yield Parameters:

Returns:

  • self

See Also:



23
24
25
26
# File 'lib/webmachine/configuration.rb', line 23

def self.configure(&block)
  application.configure(&block)
  self
end

+ (Object) render_error(code, req, res, options = {})

Renders a standard error message body for the response. The standard messages are defined in localization files.

Parameters:

  • code (Fixnum)

    the response status code

  • req (Request)

    the request object

  • req (Response)

    the response object

  • options (Hash) (defaults to: {})

    keys to override the defaults when rendering the response body



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/webmachine/errors.rb', line 14

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
end

+ (Webmachine) routes(&block)

Evaluates the passed block in the context of Dispatcher for use in adding a number of routes at once.

Returns:

See Also:



92
93
94
95
# File 'lib/webmachine/dispatcher.rb', line 92

def self.routes(&block)
  application.routes(&block)
  self
end

+ (Object) run

Starts Webmachine's default global Application serving requests



22
23
24
# File 'lib/webmachine.rb', line 22

def self.run
  application.run
end