Adds class methods to Merb::Request object. Sets up repository of session store types. Sets the session ID key and expiry values.
:api: private
# File lib/merb-core/dispatch/session.rb, line 125 def self.included(base) base.extend ClassMethods # Keep track of all known session store types. base.cattr_accessor :registered_session_types base.registered_session_types = Dictionary.new base.class_inheritable_accessor :_session_id_key, :_session_secret_key, :_session_expiry, :_session_secure, :_session_http_only, :_default_cookie_domain base._session_id_key = Merb::Config[:session_id_key] || '_session_id' base._session_expiry = Merb::Config[:session_expiry] || 0 base._session_secret_key = Merb::Config[:session_secret_key] base._session_secure = Merb::Config[:session_secure] || false base._session_http_only = Merb::Config[:session_http_only] || false base._default_cookie_domain = Merb::Config[:default_cookie_domain] end
The default session store type.
:api: private
# File lib/merb-core/dispatch/session.rb, line 162 def default_session_store Merb::Config[:session_store] && Merb::Config[:session_store].to_sym end
Teardown and/or persist the current sessions.
:api: private
# File lib/merb-core/dispatch/session.rb, line 237 def finalize_session session_stores.each { |name, store| store.finalize(self) } end
Returns session container. Merb is able to handle multiple session stores, hence a parameter to pick it.
session_store<String> |
The type of session store to access, |
defaults to default_session_store.
If no suitable session store type is given, it defaults to cookie-based sessions.
an instance of a session store extending Merb::SessionContainer. |
:api: public
# File lib/merb-core/dispatch/session.rb, line 190 def session(session_store = nil) session_store ||= default_session_store if class_name = self.class.registered_session_types[session_store] session_stores[session_store] ||= Object.full_const_get(class_name).setup(self) elsif fallback = self.class.registered_session_types.keys.first Merb.logger.warn "Session store '#{session_store}' not found. Check your configuration in init file." Merb.logger.warn "Falling back to #{fallback} session store." session(fallback) else msg = "No session store set. Set it in init file like this: c[:session_store] = 'activerecord'" Merb.logger.error!(msg) raise NoSessionContainer, msg end end
new_session<Merb::SessionContainer> |
A session store instance. |
The session is assigned internally by its session_store_type key.
:api: private
# File lib/merb-core/dispatch/session.rb, line 212 def session=(new_session) if self.session?(new_session.class.session_store_type) original_session_id = self.session(new_session.class.session_store_type).session_id if new_session.session_id != original_session_id set_session_id_cookie(new_session.session_id) end end session_stores[new_session.class.session_store_type] = new_session end
Whether a session has been setup
Boolean |
true if the session is part of the session stores configured. |
:api: private
# File lib/merb-core/dispatch/session.rb, line 228 def session?(session_store = nil) (session_store ? [session_store] : session_stores).any? do |type, store| store.is_a?(Merb::SessionContainer) end end
Generated with the Darkfish Rdoc Generator 2.