Class: Zero::Request
- Inherits:
-
Object
- Object
- Zero::Request
- Defined in:
- lib/zero/request.rb,
lib/zero/request/accept.rb,
lib/zero/request/client.rb,
lib/zero/request/server.rb,
lib/zero/request/parameter.rb,
lib/zero/request/accept_type.rb
Overview
This class wraps around a rack environment for easier access to all data.
Defined Under Namespace
Classes: Accept, AcceptType, Client, Parameter, Server
Instance Attribute Summary collapse
-
#env ⇒ Hash
readonly
get the environment.
Class Method Summary collapse
-
.__new__ ⇒ Object
replace #new with a function to reuse an already defined request.
-
.new(environment) ⇒ Object
reuse an already defined request in the environment or create a new one.
Instance Method Summary collapse
-
#accept ⇒ Accept
get the media types.
-
#client ⇒ Client
return all information about the client.
-
#content_type ⇒ String
return the content type of the request TODO change into its own object?.
-
#delete? ⇒ Boolean
is the method ‘DELETE’?.
-
#get? ⇒ Boolean
is the method ‘GET’?.
-
#head? ⇒ Boolean
is the method ‘HEAD’?.
-
#initialize(env) ⇒ Request
constructor
create a new request object.
-
#method ⇒ Symbol
get the method of the request.
-
#params ⇒ Parameter
get an object representing the parameters of the request.
-
#patch? ⇒ Boolean
is the method ‘PATCH’?.
-
#path ⇒ String
get the requested path.
-
#post? ⇒ Boolean
is the method ‘POST’?.
-
#put? ⇒ Boolean
is the method ‘PUT’?.
-
#server ⇒ Server
get the information on the server.
Constructor Details
#initialize(env) ⇒ Request
create a new request object
22 23 24 25 |
# File 'lib/zero/request.rb', line 22 def initialize(env) @env = env @env['zero.request'] = self end |
Instance Attribute Details
#env ⇒ Hash (readonly)
get the environment
29 30 31 |
# File 'lib/zero/request.rb', line 29 def env @env end |
Class Method Details
.__new__ ⇒ Object
replace #new with a function to reuse an already defined request
11 |
# File 'lib/zero/request.rb', line 11 alias_method :__new__, :new |
.new(environment) ⇒ Object
reuse an already defined request in the environment or create a new one
15 16 17 18 |
# File 'lib/zero/request.rb', line 15 def new(environment) return environment['zero.request'] if environment.has_key?('zero.request') __new__(environment) end |
Instance Method Details
#accept ⇒ Accept
get the media types
64 65 66 |
# File 'lib/zero/request.rb', line 64 def accept @accept ||= Request::Accept.new(@env) end |
#client ⇒ Client
return all information about the client
39 40 41 |
# File 'lib/zero/request.rb', line 39 def client @client ||= Request::Client.new(@env) end |
#content_type ⇒ String
return the content type of the request TODO change into its own object?
58 59 60 |
# File 'lib/zero/request.rb', line 58 def content_type @env[CONST_CONTENT_TYPE] if @env.has_key?(CONST_CONTENT_TYPE) end |
#delete? ⇒ Boolean
is the method ‘DELETE’?
84 |
# File 'lib/zero/request.rb', line 84 def delete?; method == :delete; end |
#get? ⇒ Boolean
is the method ‘GET’?
75 |
# File 'lib/zero/request.rb', line 75 def get?; method == :get; end |
#head? ⇒ Boolean
is the method ‘HEAD’?
87 |
# File 'lib/zero/request.rb', line 87 def head?; method == :head; end |
#method ⇒ Symbol
get the method of the request
70 71 72 |
# File 'lib/zero/request.rb', line 70 def method @method ||= @env[CONST_REQUEST_METHOD].downcase.to_sym end |
#params ⇒ Parameter
get an object representing the parameters of the request
51 52 53 |
# File 'lib/zero/request.rb', line 51 def params @params ||= Request::Parameter.new(@env) end |
#patch? ⇒ Boolean
is the method ‘PATCH’?
90 |
# File 'lib/zero/request.rb', line 90 def patch?; method == :patch; end |
#path ⇒ String
get the requested path
33 34 35 |
# File 'lib/zero/request.rb', line 33 def path @path ||= @env[CONST_PATH_INFO] end |
#post? ⇒ Boolean
is the method ‘POST’?
78 |
# File 'lib/zero/request.rb', line 78 def post?; method == :post; end |
#put? ⇒ Boolean
is the method ‘PUT’?
81 |
# File 'lib/zero/request.rb', line 81 def put?; method == :put; end |