| | 108 | |
| | 109 | class << self |
| | 110 | def database=(db) |
| | 111 | @database = db |
| | 112 | end |
| | 113 | def log=(log) |
| | 114 | @log = log |
| | 115 | end |
| | 116 | def conditional_connect |
| | 117 | # If database models are present, `autoload?` will return nil. |
| | 118 | unless Camping::Models.autoload? :Base |
| | 119 | require 'logger' |
| | 120 | require 'camping/session' |
| | 121 | Camping::Models::Base.establish_connection @database |
| | 122 | |
| | 123 | case @log |
| | 124 | when Logger |
| | 125 | Camping::Models::Base.logger = @log |
| | 126 | when String |
| | 127 | Camping::Models::Base.logger = Logger.new(@log == "-" ? STDOUT : @log) |
| | 128 | end |
| | 129 | |
| | 130 | begin |
| | 131 | Camping::Models::Session.create_schema |
| | 132 | rescue MissingSourceFile |
| | 133 | puts "** #$0 stopped: SQLite3 not found, please install." |
| | 134 | puts "** See http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions." |
| | 135 | exit |
| | 136 | end |
| | 137 | |
| | 138 | if @database[:adapter] == 'sqlite3' |
| | 139 | begin |
| | 140 | require 'sqlite3_api' |
| | 141 | rescue LoadError |
| | 142 | puts "!! Your SQLite3 adapter isn't a compiled extension." |
| | 143 | abort "!! Please check out http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for tips." |
| | 144 | end |
| | 145 | end |
| | 146 | end |
| | 147 | end |
| | 148 | end |