Sha256: 1d7e2e58a7a24c9a111ba5301d924e4957f561cb8748aae9fb609905a92cf4a2

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
# $Id$

require 'nitro/request'
require 'nitro/response'
require 'nitro/render'
require 'nitro/session'

require 'nitro/builders/xhtml'

module N
	
# 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.

	attr_reader :session

	# The dispatcher.

	attr_accessor :dispatcher

	# The sessions.

	attr_accessor :sessions

	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

	# Lazy lookup of the session to avoid costly cookie
	# lookup when not needed.

	def session
		return @session if @session
		return @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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.10.0 lib/nitro/context.rb
nitro-0.9.5 lib/nitro/context.rb