Changeset 225
- Timestamp:
- 09/26/2007 03:52:10 (12 months ago)
- Location:
- trunk/lib/camping
- Files:
-
- 3 modified
-
db.rb (modified) (1 diff)
-
reloader.rb (modified) (2 diffs)
-
session.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/camping/db.rb
r214 r225 75 75 Camping::S.sub! /def\s*Y[;\s]*self[;\s]*end/, $AR_EXTRAS 76 76 Object.constants.map{|c|Object.const_get(c)}.each do |c| 77 c::Models.module_eval $AR_EXTRAS if c.respond_to?(: run)77 c::Models.module_eval $AR_EXTRAS if c.respond_to?(:goes) 78 78 end -
trunk/lib/camping/reloader.rb
r208 r225 137 137 # If database models are present, `autoload?` will return nil. 138 138 unless Camping::Models.autoload? :Base 139 require 'logger'140 require 'camping/session'141 Camping::Models::Base.establish_connection @database if @database142 143 case @log144 when Logger145 Camping::Models::Base.logger = @log146 when String147 Camping::Models::Base.logger = Logger.new(@log == "-" ? STDOUT : @log)148 end149 150 Camping::Models::Session.create_schema151 152 139 if @database and @database[:adapter] == 'sqlite3' 153 140 begin … … 158 145 end 159 146 end 147 148 case @log 149 when Logger 150 Camping::Models::Base.logger = @log 151 when String 152 require 'logger' 153 Camping::Models::Base.logger = Logger.new(@log == "-" ? STDOUT : @log) 154 end 155 156 Camping::Models::Base.establish_connection @database if @database 157 158 if Camping::Models.const_defined?(:Session) 159 Camping::Models::Session.create_schema 160 end 160 161 end 161 162 end -
trunk/lib/camping/session.rb
r205 r225 12 12 # For a basic tutorial, see the *Getting Started* section of the Camping::Session module. 13 13 require 'camping' 14 require 'camping/db' 14 15 15 16 module Camping::Models … … 18 19 class Session < Base 19 20 serialize :ivars 21 # SQL injection to bypass id field checks 22 set_primary_key '"="" OR "' 23 20 24 def []=(k, v) # :nodoc: 21 25 self.ivars[k] = v … … 39 43 # If none is found, generates a new session. 40 44 def self.persist cookies 45 session = nil 41 46 if cookies.camping_sid 42 47 session = Camping::Models::Session.find_by_hashid cookies.camping_sid … … 64 69 ActiveRecord::Schema.define do 65 70 create_table :sessions, :force => true, :id => false do |t| 66 t.column :hashid, :string, :limit => 32 71 t.column :hashid, :string, :limit => 32, :null => false 67 72 t.column :created_at, :datetime 68 73 t.column :ivars, :text 69 74 end 75 add_index :sessions, [:hashid], :unique => true 70 76 end 71 77 reset_column_information … … 109 115 @state = (session[app] ||= Camping::H[]) 110 116 hash_before = Marshal.dump(@state).hash 111 s = super(*a) 117 return super(*a) 118 ensure 112 119 if session 113 120 hash_after = Marshal.dump(@state).hash … … 117 124 end 118 125 end 119 s120 126 end 121 127 end
