Skip to content

Commit

Permalink
* lib/camping.rb: only HashWithIndifferentAccess is loaded by defaul…
Browse files Browse the repository at this point in the history
…t (to assist Og users.) if you use ActiveRecord, though, all of ActiveSupport will be loaded.

 * lib/camping/db.rb: ditto.
 * bin/camping: moved all database code into the Reloader so you, Mr. Tim Bray, can mount many database-free apps without inconvenience.  really this is for zimbatm, author of Equipment, who has been tremendously resourceful and cunning of late!
 * lib/camping/reloader.rb: ditto.
 * Rakefile: allow ActiveSupport 1.3.1.
  • Loading branch information
_why committed Jul 11, 2006
1 parent 1dc82b2 commit 7901099
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec =
s.homepage = 'http://code.whytheluckystiff.net/camping/'
s.executables = ['camping']

s.add_dependency('activesupport', '>1.3.1')
s.add_dependency('activesupport', '>=1.3.1')
s.add_dependency('markaby', '>0.4')
s.add_dependency('metaid')
s.required_ruby_version = '>= 1.8.2'
Expand Down
24 changes: 2 additions & 22 deletions bin/camping
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require 'ostruct'
require 'stringio'
require 'rubygems'
require 'camping'
require 'camping/session'
require 'camping/reloader'
require 'yaml'

Expand Down Expand Up @@ -77,27 +76,6 @@ end
unless conf.database
conf.database = {:adapter => 'sqlite3', :database => conf.db}
end
Camping::Models::Base.establish_connection conf.database

if conf.log
Camping::Models::Base.logger = Logger.new(conf.log == "-" ? STDOUT : conf.log)
end
begin
Camping::Models::Session.create_schema
rescue MissingSourceFile
puts "** #$0 stopped: SQLite3 not found, please install."
puts "** See http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions."
exit
end

if conf.database[:adapter] == 'sqlite3'
begin
require 'sqlite3_api'
rescue LoadError
puts "!! Your SQLite3 adapter isn't a compiled extension."
abort "!! Please check out http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for tips."
end
end

apps = ARGV.inject([]) do |apps, script|
if File.directory? script
Expand All @@ -107,6 +85,8 @@ apps = ARGV.inject([]) do |apps, script|
end
end

Camping::Reloader.database = conf.database
Camping::Reloader.log = conf.log
apps.map! { |script| Camping::Reloader.new(script) }
abort("** No apps successfully loaded") unless apps.detect { |app| app.klass }

Expand Down
2 changes: 1 addition & 1 deletion lib/camping.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%w[active_support markaby metaid tempfile uri].map{|l|require l}
%w[active_support/core_ext/hash markaby metaid tempfile uri].map{|l|require l}
module Camping;Apps=[];C=self;S=IO.read(__FILE__).sub(/S=I.+$/,'')
P="Cam\ping Problem!";module Helpers;def R c,*g;p=/\(.+?\)/;g.inject(c.
urls.find{|x|x.scan(p).size==g.size}.dup){|s,a|s.sub p,C.escape((a[
Expand Down
2 changes: 1 addition & 1 deletion lib/camping/db.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'active_record'
%w[active_support active_record].map{|l|require l}
module Camping::Models
A = ActiveRecord
Base = A::Base
Expand Down
43 changes: 43 additions & 0 deletions lib/camping/reloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def load_app
@klass = nil
return
end

Reloader.conditional_connect
@klass.create if @klass.respond_to? :create
@klass
end
Expand Down Expand Up @@ -103,5 +105,46 @@ def run(*a)
def view_source
File.read(@script)
end

class << self
def database=(db)
@database = db
end
def log=(log)
@log = log
end
def conditional_connect
# If database models are present, `autoload?` will return nil.
unless Camping::Models.autoload? :Base
require 'logger'
require 'camping/session'
Camping::Models::Base.establish_connection @database

case @log
when Logger
Camping::Models::Base.logger = @log
when String
Camping::Models::Base.logger = Logger.new(@log == "-" ? STDOUT : @log)
end

begin
Camping::Models::Session.create_schema
rescue MissingSourceFile
puts "** #$0 stopped: SQLite3 not found, please install."
puts "** See http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions."
exit
end

if @database[:adapter] == 'sqlite3'
begin
require 'sqlite3_api'
rescue LoadError
puts "!! Your SQLite3 adapter isn't a compiled extension."
abort "!! Please check out http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for tips."
end
end
end
end
end
end
end

0 comments on commit 7901099

Please sign in to comment.