Class: Waves::Request

Inherits:
Object show all
Defined in:
lib/runtime/request.rb

Overview

Waves::Request represents an HTTP request and provides convenient methods for accessing request attributes. See Rack::Request for documentation of any method not defined here.

Defined Under Namespace

Classes: ParseError

Constant Summary collapse

METHODS =

Supported request methods

%w{get post put delete head options trace}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Create a new request. Takes a env parameter representing the request passed in from Rack. You shouldn’t need to call this directly.



11
12
13
14
15
16
# File 'lib/runtime/request.rb', line 11

def initialize( env )
  @request = Rack::Request.new( env )
  @response = Waves::Response.new( self )
  @session = Waves::Session.new( self )
  @blackboard = Waves::Blackboard.new( self )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Accessor not explicitly defined by Waves::Request are delegated to Rack::Request. Check the Rack documentation for more information.



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

def method_missing(name,*args)
  @request.send(name,*args)
end

Instance Attribute Details

#blackboardObject (readonly)

Returns the value of attribute blackboard.



7
8
9
# File 'lib/runtime/request.rb', line 7

def blackboard
  @blackboard
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/runtime/request.rb', line 7

def response
  @response
end

#sessionObject (readonly)

Returns the value of attribute session.



7
8
9
# File 'lib/runtime/request.rb', line 7

def session
  @session
end

Instance Method Details

#content_typeObject

The request content type.



37
38
39
# File 'lib/runtime/request.rb', line 37

def content_type
  @request.env['CONTENT_TYPE']
end

#domainObject

The request domain. Ex: www.fubar.com



32
33
34
# File 'lib/runtime/request.rb', line 32

def domain
  @request.host
end

#methodObject

The request method. Because browsers can’t send PUT or DELETE requests this can be simulated by sending a POST with a hidden field named ‘_method’ and a value with ‘PUT’ or ‘DELETE’. Also accepted is when a query parameter named ‘_method’ is provided.



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/runtime/request.rb', line 53

def method
  @method ||= begin
    request_method = @request.request_method.downcase
    if request_method == 'post'
      _method = @request['_method']
      _method.downcase! if _method
      METHODS.include?(_method) ? _method.intern : :post
    else
      request_method.intern
    end
  end
end

#not_foundObject

Raise a not found exception.



67
68
69
# File 'lib/runtime/request.rb', line 67

def not_found
  raise Waves::Dispatchers::NotFoundError.new( @request.url + ' not found.' )
end

#pathObject

The request path (PATH_INFO). Ex: /entry/2008-01-17



27
28
29
# File 'lib/runtime/request.rb', line 27

def path
  @request.path_info
end

#rack_requestObject



18
# File 'lib/runtime/request.rb', line 18

def rack_request; @request; end

#redirect(path, status = '302') ⇒ Object

Issue a redirect for the given path.



72
73
74
# File 'lib/runtime/request.rb', line 72

def redirect( path, status = '302' )
  raise Waves::Dispatchers::Redirect.new( path, status )
end