Class: CGI::Session::ActiveRecordStore::Session

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/action_controller/session/active_record_store.rb

Overview

The default Active Record class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_table!Object


68
69
70
71
72
73
74
75
76
# File 'lib/action_controller/session/active_record_store.rb', line 68

def create_table!
  connection.execute <<-end_sql
    CREATE TABLE #{table_name} (
      id INTEGER PRIMARY KEY,
      #{connection.quote_column_name('session_id')} TEXT UNIQUE,
      #{connection.quote_column_name('data')} TEXT(255)
    )
  end_sql
end

.data_column_size_limitObject


54
55
56
# File 'lib/action_controller/session/active_record_store.rb', line 54

def data_column_size_limit
  columns_hash['data'].limit
end

.drop_table!Object


78
79
80
# File 'lib/action_controller/session/active_record_store.rb', line 78

def drop_table!
  connection.execute "DROP TABLE #{table_name}"
end

.find_by_session_id(session_id) ⇒ Object

Hook to set up sessid compatibility.


59
60
61
62
# File 'lib/action_controller/session/active_record_store.rb', line 59

def find_by_session_id(session_id)
  setup_sessid_compatibility!
  find_by_session_id(session_id)
end

.fingerprint(data) ⇒ Object


66
# File 'lib/action_controller/session/active_record_store.rb', line 66

def fingerprint(data) Digest::MD5.hexdigest(data)         end

.marshal(data) ⇒ Object


64
# File 'lib/action_controller/session/active_record_store.rb', line 64

def marshal(data)     Base64.encode64(Marshal.dump(data)) end

.reloadable?Boolean

Don't try to reload ARStore::Session in dev mode.

Returns:

  • (Boolean)

50
51
52
# File 'lib/action_controller/session/active_record_store.rb', line 50

def reloadable? #:nodoc:
  false
end

.unmarshal(data) ⇒ Object


65
# File 'lib/action_controller/session/active_record_store.rb', line 65

def unmarshal(data)   Marshal.load(Base64.decode64(data)) end

Instance Method Details

#dataObject

Lazy-unmarshal session state. Take a fingerprint so we can detect whether to save changes later.


104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/action_controller/session/active_record_store.rb', line 104

def data
  unless @data
    case @data = read_attribute('data')
      when String
        @fingerprint = self.class.fingerprint(@data)
        @data = self.class.unmarshal(@data)
      when nil
        @data = {}
        @fingerprint = nil
    end
  end
  @data
end