Class: NYNY::RequestScope
- Inherits:
-
Object
- Object
- NYNY::RequestScope
- Defined in:
- lib/nyny/request_scope.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_to(&handler) ⇒ Object
- #cookies ⇒ Object
- #halt(status, headers = {}, body = '') ⇒ Object
- #headers(hash = {}) ⇒ Object
-
#initialize(request) ⇒ RequestScope
constructor
A new instance of RequestScope.
- #params ⇒ Object
- #redirect_to(uri, status = 302) ⇒ Object (also: #redirect)
- #session ⇒ Object
- #status(code) ⇒ Object
Constructor Details
#initialize(request) ⇒ RequestScope
Returns a new instance of RequestScope.
9 10 11 12 |
# File 'lib/nyny/request_scope.rb', line 9 def initialize request @request = request @response = Response.new '', 200, {'Content-Type' => 'text/html'} end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/nyny/request_scope.rb', line 3 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/nyny/request_scope.rb', line 3 def response @response end |
Class Method Details
.add_helper_module(m) ⇒ Object
5 6 7 |
# File 'lib/nyny/request_scope.rb', line 5 def self.add_helper_module m include m end |
Instance Method Details
#apply_to(&handler) ⇒ Object
46 47 48 49 50 |
# File 'lib/nyny/request_scope.rb', line 46 def apply_to &handler response.body = instance_eval(&handler) .each {|k,v| response. k,v } response end |
#cookies ⇒ Object
26 27 28 |
# File 'lib/nyny/request_scope.rb', line 26 def request. end |
#halt(status, headers = {}, body = '') ⇒ Object
34 35 36 37 38 39 |
# File 'lib/nyny/request_scope.rb', line 34 def halt status, headers={}, body='' response.status = status response.headers.merge! headers response.body = body throw :halt, response end |
#headers(hash = {}) ⇒ Object
18 19 20 |
# File 'lib/nyny/request_scope.rb', line 18 def headers hash={} response.headers.merge! hash end |
#params ⇒ Object
14 15 16 |
# File 'lib/nyny/request_scope.rb', line 14 def params request.params end |
#redirect_to(uri, status = 302) ⇒ Object Also known as: redirect
41 42 43 |
# File 'lib/nyny/request_scope.rb', line 41 def redirect_to uri, status=302 halt status, {'Location' => uri} end |
#session ⇒ Object
22 23 24 |
# File 'lib/nyny/request_scope.rb', line 22 def session request.session end |
#status(code) ⇒ Object
30 31 32 |
# File 'lib/nyny/request_scope.rb', line 30 def status code response.status = code end |