Module: Merb::SessionMixin

Defined in:
merb-core/lib/merb-core/dispatch/session.rb

Overview

This is mixed into Merb::Controller on framework boot.

Defined Under Namespace

Modules: RequestMixin Classes: NoSessionContainer, SessionOverflow

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
# File 'merb-core/lib/merb-core/dispatch/session.rb', line 56

def self.included(base)
  # Register a callback to finalize sessions - needs to run before the cookie
  # callback extracts Set-Cookie headers from request.cookies.
  base._after_dispatch_callbacks.unshift lambda { |c| c.request.finalize_session }
end

+ (Object) needs_new_cookie!

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Marks this session as needing a new cookie.



99
100
101
# File 'merb-core/lib/merb-core/dispatch/session.rb', line 99

def needs_new_cookie!
  @_new_cookie = true
end

+ (Boolean) needs_new_cookie?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Does session need new cookie?



108
109
110
# File 'merb-core/lib/merb-core/dispatch/session.rb', line 108

def needs_new_cookie?
  @_new_cookie
end

+ (String) rand_uuid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns A random 32 character string for use as a unique session ID.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'merb-core/lib/merb-core/dispatch/session.rb', line 79

def rand_uuid
  if defined?(SecureRandom)
    SecureRandom.hex(16)
  else
    values = [
      rand(0x0010000),
      rand(0x0010000),
      rand(0x0010000),
      rand(0x0010000),
      rand(0x0010000),
      rand(0x1000000),
      rand(0x1000000),
    ]
    "%04x%04x%04x%04x%04x%06x%06x" % values
  end
end

Instance Method Details

- (SessionContainer) session(session_store = nil)

Returns The session that was extracted from the request object.



68
69
70
# File 'merb-core/lib/merb-core/dispatch/session.rb', line 68

def session(session_store = nil)
  request.session(session_store)
end