The mixin that adds methods to Strelka::HTTPRequest for session management.
request.session? request.session
The current session namespace
Extension callback – add instance variables to extended objects.
# File lib/strelka/httprequest/session.rb, line 21
def initialize( * )
super
@session_namespace = nil
@session = nil
end
Return the session associated with the request, creating it if necessary.
# File lib/strelka/httprequest/session.rb, line 60
def session
unless @session
@session = Strelka::App::Sessions.session_class.load_or_create( self )
@session.namespace = self.session_namespace
end
return @session
end
Set the request's session object.
# File lib/strelka/httprequest/session.rb, line 71
def session=( new_session )
new_session.namespace = self.session_namespace if new_session.respond_to?( :namespace )
@session = new_session
end
Returns true
if the request has an associated session object.
# File lib/strelka/httprequest/session.rb, line 47
def session?
return @session || Strelka::App::Sessions.session_class.has_session_for?( self )
end
Returns true
if the request has loaded its session.
# File lib/strelka/httprequest/session.rb, line 54
def session_loaded?
return @session ? true : false
end
The namespace that will be used when creating a session for this request
# File lib/strelka/httprequest/session.rb, line 37
def session_namespace=( namespace )
self.log.debug "Setting session namespace to %p" % [ namespace ]
@session_namespace = namespace
# If the session has already been created, switch its current namespace
@session.namespace = namespace if @session
end