Class: NYNY::RequestScope
- Inherits:
-
Object
- Object
- NYNY::RequestScope
- Extended by:
- Forwardable
- 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.
Instance Method Summary collapse
- #apply_to(&handler) ⇒ Object
- #cookies ⇒ Object
- #halt(status, headers = {}, body = '') ⇒ Object
-
#initialize(env) ⇒ RequestScope
constructor
A new instance of RequestScope.
- #redirect_to(uri, status = 302) ⇒ Object (also: #redirect)
- #status(code) ⇒ Object
Constructor Details
#initialize(env) ⇒ RequestScope
Returns a new instance of RequestScope.
12 13 14 15 16 |
# File 'lib/nyny/request_scope.rb', line 12 def initialize env @request = Request.new(env) @request.params.merge! env['nyny.params'] @response = Response.new [], 200, {'Content-Type' => 'text/html'} end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/nyny/request_scope.rb', line 8 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/nyny/request_scope.rb', line 8 def response @response end |
Instance Method Details
#apply_to(&handler) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/nyny/request_scope.rb', line 37 def apply_to &handler data = instance_eval(&handler) data.respond_to?(:each) ? response.body = data : response.write(data) .finish!(response) if @cookies response end |
#cookies ⇒ Object
18 19 20 |
# File 'lib/nyny/request_scope.rb', line 18 def @cookies ||= Rack::Cookies::CookieJar.new(request.) end |
#halt(status, headers = {}, body = '') ⇒ Object
26 27 28 29 30 |
# File 'lib/nyny/request_scope.rb', line 26 def halt status, headers={}, body='' @response = Response.new body, status, headers .finish!(response) if @cookies throw :halt, response end |
#redirect_to(uri, status = 302) ⇒ Object Also known as: redirect
32 33 34 |
# File 'lib/nyny/request_scope.rb', line 32 def redirect_to uri, status=302 halt status, {'Location' => uri} end |
#status(code) ⇒ Object
22 23 24 |
# File 'lib/nyny/request_scope.rb', line 22 def status code response.status = code end |