Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 10
- Log:
Checking in HEAD from RForum's SVN of 22-Jul-2006, 8pm (revision 906).
- Author:
- adh
- Date:
- Sat Jul 22 20:02:44 +0100 2006
- Size:
- 3982 Bytes
- Properties:
- Property svn:executable is set to *
1 | # This software is released under the MIT license |
2 | # |
3 | # Copyright (c) 2005 Stefan Kaes |
4 | |
5 | # Permission is hereby granted, free of charge, to any person obtaining |
6 | # a copy of this software and associated documentation files (the |
7 | # "Software"), to deal in the Software without restriction, including |
8 | # without limitation the rights to use, copy, modify, merge, publish, |
9 | # distribute, sublicense, and/or sell copies of the Software, and to |
10 | # permit persons to whom the Software is furnished to do so, subject to |
11 | # the following conditions: |
12 | |
13 | # The above copyright notice and this permission notice shall be |
14 | # included in all copies or substantial portions of the Software. |
15 | |
16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
23 | |
24 | |
25 | require 'active_record' |
26 | require 'cgi' |
27 | require 'cgi/session' |
28 | require 'base64' |
29 | |
30 | # +SQLSessionStore+ is a stripped down, optimized for speed version of |
31 | # class +ActiveRecordStore+, as it did exist in Rails version |
32 | # 0.12. Since then, +ActiveRecordStore+ has undergone many changes, |
33 | # not all them for the better. |
34 | |
35 | class SQLSessionStore |
36 | |
37 | # An ActiveRecord class which corresponds to the database table |
38 | # +sessions+. Functions +find_session+, +create_session+, |
39 | # +update_session+ and +destroy+ constitute the interface to class |
40 | # +SQLSessionStore+. |
41 | |
42 | class Session < ActiveRecord::Base |
43 | |
44 | # retrieve session data for a given +session_id+ from the database, |
45 | # return nil if no such session exists |
46 | def self.find_session(session_id) |
47 | find_first("sessid='#{session_id}'") |
48 | end |
49 | |
50 | # create a new session with given +id+ and +data+ |
51 | def self.create_session(session_id, data) |
52 | new(:sessid => session_id, :data => data) |
53 | end |
54 | |
55 | # update session data and store it in the database |
56 | def update_session(data) |
57 | update_attribute('data', data) |
58 | end |
59 | end |
60 | |
61 | # The class to be used for creating, retrieving and updating sessions. |
62 | # Defaults to SQLSessionStore::Session, which is derived from +ActiveRecord::Base+. |
63 | # |
64 | # In order to achieve acceptable performance you should implement |
65 | # your own session class, similar to the one provided for Myqsl. |
66 | # |
67 | # Only functions +find_session+, +create_session+, |
68 | # +update_session+ and +destroy+ are required. See file +mysql_session.rb+. |
69 | |
70 | cattr_accessor :session_class |
71 | @@session_class = SQLSessionStore::Session |
72 | |
73 | # Create a new SQLSessionStore instance. |
74 | # |
75 | # +session+ is the session for which this instance is being created. |
76 | # |
77 | # +option+ is currently ignored as no options are recognized. |
78 | |
79 | def initialize(session, option=nil) |
80 | if @session = @@session_class.find_session(session.session_id) |
81 | @data = unmarshalize(@session.data) |
82 | else |
83 | @session = @@session_class.create_session(session.session_id, marshalize({})) |
84 | @data = {} |
85 | end |
86 | end |
87 | |
88 | # Update the database and disassociate the session object |
89 | def close |
90 | if @session |
91 | @session.update_session(marshalize(@data)) |
92 | @session = nil |
93 | end |
94 | end |
95 | |
96 | # Delete the current session, disassociate and destroy session object |
97 | def delete |
98 | if @session |
99 | @session.destroy |
100 | @session = nil |
101 | end |
102 | end |
103 | |
104 | # Restore session data from the session object |
105 | def restore |
106 | if @session |
107 | @data = unmarshalize(@session.data) |
108 | end |
109 | end |
110 | |
111 | # Save session data in the session object |
112 | def update |
113 | if @session |
114 | @session.update_session(marshalize(@data)) |
115 | end |
116 | end |
117 | |
118 | private |
119 | def unmarshalize(data) |
120 | Marshal.load(Base64.decode64(data)) |
121 | end |
122 | |
123 | def marshalize(data) |
124 | Base64.encode64(Marshal.dump(data)) |
125 | end |
126 | |
127 | end |