### Home Classes Methods

### In Files

- lib/merb-core/dispatch/session.rb

### Namespace

- MODULE Merb::SessionMixin::RequestMixin::ClassMethods

### Methods

- ::included
- #default_cookies
- #default_session_store
- #destroy_session_cookie
- #finalize_session
- #finalize_sessions
- #session
- #session=
- #session?
- #session_cookie_value
- #session_id
- #session_stores
- #set_session_cookie_value
- #set_session_id_cookie

### Files

- CHANGELOG
- LICENSE
- README
- TODO

### Class/Module Index

Quicksearch

- Merb
- Merb::AbstractController
- Merb::AcceptType
- Merb::AuthenticationMixin
- Merb::AuthenticationMixin::BasicAuthentication
- Merb::BootLoader
- Merb::BootLoader::AfterAppLoads
- Merb::BootLoader::BackgroundServices
- Merb::BootLoader::BeforeAppLoads
- Merb::BootLoader::BuildFramework
- Merb::BootLoader::ChooseAdapter
- Merb::BootLoader::Cookies
- Merb::BootLoader::Defaults
- Merb::BootLoader::Dependencies
- Merb::BootLoader::DropPidFile
- Merb::BootLoader::LoadClasses
- Merb::BootLoader::Logger
- Merb::BootLoader::MimeTypes
- Merb::BootLoader::MixinSession
- Merb::BootLoader::RackUpApplication
- Merb::BootLoader::ReloadClasses
- Merb::BootLoader::ReloadClasses::TimedExecutor
- Merb::BootLoader::Router
- Merb::BootLoader::SetupSession
- Merb::BootLoader::SetupStubClasses
- Merb::BootLoader::Templates
- Merb::ConditionalGetMixin
- Merb::Config
- Merb::Config::ConfigBlock
- Merb::Const
- Merb::Controller
- Merb::ControllerExceptions
- Merb::ControllerExceptions::Accepted
- Merb::ControllerExceptions::ActionNotFound
- Merb::ControllerExceptions::BadGateway
- Merb::ControllerExceptions::BadRequest
- Merb::ControllerExceptions::Base
- Merb::ControllerExceptions::ClientError
- Merb::ControllerExceptions::Conflict
- Merb::ControllerExceptions::Continue
- Merb::ControllerExceptions::Created
- Merb::ControllerExceptions::ExpectationFailed
- Merb::ControllerExceptions::Forbidden
- Merb::ControllerExceptions::GatewayTimeout
- Merb::ControllerExceptions::Gone
- Merb::ControllerExceptions::HTTPVersionNotSupported
- Merb::ControllerExceptions::Informational
- Merb::ControllerExceptions::InternalServerError
- Merb::ControllerExceptions::LayoutNotFound
- Merb::ControllerExceptions::LengthRequired
- Merb::ControllerExceptions::MethodNotAllowed
- Merb::ControllerExceptions::MovedPermanently
- Merb::ControllerExceptions::MovedTemporarily
- Merb::ControllerExceptions::MultiPartParseError
- Merb::ControllerExceptions::MultipleChoices
- Merb::ControllerExceptions::NoContent
- Merb::ControllerExceptions::NonAuthoritativeInformation
- Merb::ControllerExceptions::NotAcceptable
- Merb::ControllerExceptions::NotFound
- Merb::ControllerExceptions::NotImplemented
- Merb::ControllerExceptions::NotModified
- Merb::ControllerExceptions::OK
- Merb::ControllerExceptions::PartialContent
- Merb::ControllerExceptions::PaymentRequired
- Merb::ControllerExceptions::PreconditionFailed
- Merb::ControllerExceptions::ProxyAuthenticationRequired
- Merb::ControllerExceptions::Redirection
- Merb::ControllerExceptions::RequestEntityTooLarge
- Merb::ControllerExceptions::RequestRangeNotSatisfiable
- Merb::ControllerExceptions::RequestTimeout
- Merb::ControllerExceptions::RequestURITooLarge
- Merb::ControllerExceptions::ResetContent
- Merb::ControllerExceptions::SeeOther
- Merb::ControllerExceptions::ServerError
- Merb::ControllerExceptions::ServiceUnavailable
- Merb::ControllerExceptions::Successful
- Merb::ControllerExceptions::SwitchingProtocols
- Merb::ControllerExceptions::TemplateNotFound
- Merb::ControllerExceptions::TemporaryRedirect
- Merb::ControllerExceptions::Unauthorized
- Merb::ControllerExceptions::UnsupportedMediaType
- Merb::ControllerExceptions::UseProxy
- Merb::ControllerMixin
- Merb::CookieSession
- Merb::CookieSession::CookieOverflow
- Merb::CookieSession::TamperedWithCookie
- Merb::Cookies
- Merb::CookiesMixin
- Merb::CookiesMixin::RequestMixin
- Merb::Counter
- Merb::Dispatcher
- Merb::Dispatcher::DefaultException
- Merb::Dispatcher::DefaultExceptionHelper
- Merb::GlobalHelpers
- Merb::InlineTemplates
- Merb::Logger
- Merb::MemcacheSession
- Merb::MemcacheStore
- Merb::MemorySession
- Merb::MemorySessionStore
- Merb::Parse
- Merb::Plugins
- Merb::Rack
- Merb::Rack::AbstractAdapter
- Merb::Rack::Adapter
- Merb::Rack::Application
- Merb::Rack::ConditionalGet
- Merb::Rack::Console
- Merb::Rack::ContentLength
- Merb::Rack::DeferrableMiddleware
- Merb::Rack::Ebb
- Merb::Rack::EventedMongrel
- Merb::Rack::FastCGI
- Merb::Rack::Handler
- Merb::Rack::Handler::Mongrel
- Merb::Rack::Head
- Merb::Rack::Helpers
- Merb::Rack::Irb
- Merb::Rack::Middleware
- Merb::Rack::Mongrel
- Merb::Rack::PathPrefix
- Merb::Rack::Profiler
- Merb::Rack::Runner
- Merb::Rack::Static
- Merb::Rack::StreamWrapper
- Merb::Rack::SwiftipliedMongrel
- Merb::Rack::Thin
- Merb::Rack::ThinTurbo
- Merb::Rack::Tracer
- Merb::Rack::WEBrick
- Merb::RenderMixin
- Merb::RenderMixin::ClassMethods
- Merb::Request
- Merb::ReservedError
- Merb::Responder
- Merb::ResponderMixin
- Merb::ResponderMixin::ClassMethods
- Merb::ResponderMixin::ContentTypeAlreadySet
- Merb::Router
- Merb::Router::Behavior
- Merb::Router::Behavior::Error
- Merb::Router::Behavior::Proxy
- Merb::Router::CachedProc
- Merb::Router::GenerationError
- Merb::Router::NotCompiledError
- Merb::Router::Resources
- Merb::Router::RouteNotFound
- Merb::Server
- Merb::Session
- Merb::SessionContainer
- Merb::SessionMixin
- Merb::SessionMixin::NoSessionContainer
- Merb::SessionMixin::RequestMixin
- Merb::SessionMixin::RequestMixin::ClassMethods
- Merb::SessionMixin::SessionOverflow
- Merb::SessionStoreContainer
- Merb::System
- Merb::System::PortablePoller
- Merb::Template
- Merb::Template::Erubis
- Merb::Template::Erubis::Mixin
- Merb::Test
- Merb::Test::ControllerHelper
- Merb::Test::Cookie
- Merb::Test::CookieJar
- Merb::Test::ExampleGroup
- Merb::Test::Helpers
- Merb::Test::MakeRequest
- Merb::Test::Matchers
- Merb::Test::MultipartRequestHelper
- Merb::Test::MultipartRequestHelper::FileParam
- Merb::Test::MultipartRequestHelper::Param
- Merb::Test::MultipartRequestHelper::Post
- Merb::Test::RequestHelper
- Merb::Test::RequestHelper::CookieJar
- Merb::Test::RequestHelper::FakeRequest
- Merb::Test::RouteHelper
- Merb::Test::Rspec
- Merb::Test::Rspec::ControllerMatchers
- Merb::Test::Rspec::ControllerMatchers::BeError
- Merb::Test::Rspec::ControllerMatchers::BeRedirect
- Merb::Test::Rspec::ControllerMatchers::Provide
- Merb::Test::Rspec::RouteMatchers
- Merb::Test::Rspec::RouteMatchers::ParameterMatcher
- Merb::Test::Rspec::RouteMatchers::RouteToMatcher
- Merb::Test::ViewHelper
- Merb::Test::WebratHelper
- Merb::Worker
- Erubis
- Erubis::Basic
- Erubis::Basic::Converter
- Erubis::BlockAwareEnhancer
- Erubis::BlockAwareEruby
- Erubis::MEruby
- Spec
- Spec::Matchers
- Spec::Matchers::MatcherDSL
- Spec::Runner
- Spec::Runner::Formatter
- Spec::Runner::Formatter::BaseTextFormatter
- Gem
- Gem::Dependency
- Hpricot
- Hpricot::Elem
- Mongrel
- Mongrel::HttpResponse
- Class
- Exception
- Hash
- Kernel
- MemCache
- Memcached
- Object
- String
- Time

No matching classes.

# Merb::SessionMixin::RequestMixin

### Public Class Methods

included(base) click to toggle source

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

### Public Instance Methods

default_cookies() click to toggle source

Assign default cookie values

:api: private

    # File lib/merb-core/dispatch/session.rb, line 245
    def default_cookies
      defaults = {}
      if route && route.allow_fixation? && params.key?(_session_id_key)
        Merb.logger.info("Fixated session id: #{_session_id_key}")
        defaults[_session_id_key] = params[_session_id_key]
      end
      defaults
    end

default_session_store() click to toggle source

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

destroy_session_cookie() click to toggle source

Destroy the session cookie.

:api: private

    # File lib/merb-core/dispatch/session.rb, line 283
    def destroy_session_cookie
      cookies.delete(_session_id_key)
    end

finalize_session() click to toggle source

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

Also aliased as: finalize_sessions
finalize_sessions() click to toggle source
Alias for: finalize_session
session(session_store = nil) click to toggle source

Returns session container. Merb is able to handle multiple session stores, hence a parameter to pick it.

#### Parameters

session_store<String> | The type of session store to access,

defaults to default_session_store.

### Notes

If no suitable session store type is given, it defaults to cookie-based sessions.

#### Returns

SessionContainer | 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

session=(new_session) click to toggle source

#### Parameters

new_session<Merb::SessionContainer> | A session store instance.

### Notes

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

session?(session_store = nil) click to toggle source

Whether a session has been setup

#### Returns

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

session_cookie_value() click to toggle source

#### Returns

String | The value of the session cookie; either the session id or the actual encoded data.

:api: private

    # File lib/merb-core/dispatch/session.rb, line 275
    def session_cookie_value
      cookies[_session_id_key]
    end

Also aliased as: session_id
session_id() click to toggle source
Alias for: session_cookie_value
session_stores() click to toggle source

#### Returns

Hash | All active session stores by type.

:api: private

    # File lib/merb-core/dispatch/session.rb, line 170
    def session_stores
      @session_stores ||= {}
    end

set_session_cookie_value(value, options = {}) click to toggle source

Sets session cookie value.

#### Parameters

value<String> | The value of the session cookie; either the session id or the actual encoded data.
options<Hash> | Cookie options like domain, path and expired.

:api: private

    # File lib/merb-core/dispatch/session.rb, line 261
    def set_session_cookie_value(value, options = {})
      defaults = {}
      defaults[:expires]   = Time.now + _session_expiry if _session_expiry > 0
      defaults[:domain]    = _default_cookie_domain if _default_cookie_domain
      defaults[:secure]    = _session_secure
      defaults[:http_only] = _session_http_only
      cookies.set_cookie(_session_id_key, value, defaults.merge(options))
    end

Also aliased as: set_session_id_cookie
set_session_id_cookie(value, options = {}) click to toggle source
Alias for: set_session_cookie_value

[Validate]

Generated with the Darkfish Rdoc Generator 2.