Sha256: 4a69a63fbf3d3519c1db5e75414771d82a2ca469adf349a9ce9bf442c7a5617a
Contents?: true
Size: 1.88 KB
Versions: 4
Compression:
Stored size: 1.88 KB
Contents
require 'nitro/request' require 'nitro/response' require 'nitro/render' require 'nitro/session' require 'nitro/output' require 'nitro/adapter/cgi.rb' module Nitro # Encapsulates an HTTP processing cycle context. # Integrates the Request and the Response. class Context include Request include Response include Render # The configuration parameters. attr_accessor :conf # The session contains variables that stay alive # for the full user session. Session variables # should be generally avoided. This variable # becomes populated ONLY if needed. attr_reader :session # The dispatcher. attr_accessor :dispatcher def initialize(conf) @conf = conf @dispatcher = @conf.dispatcher @context = self # initialize response. @status = CgiUtils::STATUS_OK @response_headers = { 'Content-Type' => 'text/html' } # initialize the output buffer. @out = OutputBuffer.new end # Close the context, should be called at the # end of the HTTP request handling code. def close @session.sync if @session end alias_method :finish, :close #-- # FIXME: something more elegant/efficient. #++ def out if @out == '(error)' @out = '' render '/error' @out else @out end end # Lazy lookup of the session to avoid costly cookie # lookup when not needed. def session @session || @session = Session.lookup(self) end # Populate an object from request parameters. # This is a truly dangerous method. EXCLUDED_PARAMETERS = %w{ oid name } 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 alias_method :populate, :fill end end # * George Moschovitis <gm@navel.gr>
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.18.1 | lib/nitro/context.rb |
nitro-0.18.0 | lib/nitro/context.rb |
nitro-0.19.0 | lib/nitro/context.rb |
nitro-0.20.0 | lib/nitro/context.rb |