Class: N::Context
- Defined in:
- lib/nitro/context.rb
Overview
Encapsulates an HTTP processing cycle context. Integrates the Request and the Response.
Constant Summary collapse
- EXCLUDED_PARAMETERS =
Populate an object from request parameters. This is a truly dangerous method.
%w{ oid name }
Instance Attribute Summary collapse
-
#conf ⇒ Object
The configuration parameters.
-
#dispatcher ⇒ Object
The dispatcher.
-
#session ⇒ Object
readonly
Lazy lookup of the session to avoid costly cookie lookup when not needed.
-
#sessions ⇒ Object
The sessions.
Attributes included from Render
#context, #out, #rendering_errors, #request
Attributes included from Response
#response_cookies, #response_headers, #status
Attributes included from Request
#cookies, #headers, #in, #params
Instance Method Summary collapse
- #fill(obj, name = nil) ⇒ Object (also: #populate)
-
#initialize(conf) ⇒ Context
constructor
A new instance of Context.
Methods included from Render
#log_error, #redirect, #redirect_referer, #render
Methods included from Response
Methods included from Request
#[], #[]=, #host, #host_url, #method, #path, #port, #protocol, #query_string, #referer, #remote_ip, #ssl?, #uri
Constructor Details
#initialize(conf) ⇒ Context
Returns a new instance of Context.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nitro/context.rb', line 40 def initialize(conf) @conf = conf @dispatcher = @conf.dispatcher @context = self @sessions = Session.manager # gmosx, FIXME: try to avoid creating this hash! @response_headers = {} @out = XhtmlString.new end |
Instance Attribute Details
#conf ⇒ Object
The configuration parameters.
24 25 26 |
# File 'lib/nitro/context.rb', line 24 def conf @conf end |
#dispatcher ⇒ Object
The dispatcher.
34 35 36 |
# File 'lib/nitro/context.rb', line 34 def dispatcher @dispatcher end |
#session ⇒ Object (readonly)
Lazy lookup of the session to avoid costly cookie lookup when not needed.
30 31 32 |
# File 'lib/nitro/context.rb', line 30 def session @session end |
#sessions ⇒ Object
The sessions.
38 39 40 |
# File 'lib/nitro/context.rb', line 38 def sessions @sessions end |
Instance Method Details
#fill(obj, name = nil) ⇒ Object Also known as: populate
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/nitro/context.rb', line 64 def fill(obj, name = nil) # if an object is passed create an instance. obj = obj.new if obj.is_a?(Class) @params.each do |param, val| begin # gmosx: DO NOT escape by default !!! if not EXCLUDED_PARAMETERS.include?(param) obj.send("__force_#{param}", val) end rescue NameError next end end return obj end |