require 'rubygems' require 'camping' require 'camping/session' require 'bivouac' include Bivouac ENV['BIVOUAC_ROOT'] = File.expand_path( File.dirname(__FILE__) ) task :environment do Camping.goes :BivouacSample # Load models from app/models files( 'models' ) { |file| require( file ) } # Load create files( '../db' ) { |file| require( file ) } # Load database schema from db/migrate files( '../db/migrate' ) { |file| require( file ) } require "#{ENV['BIVOUAC_ROOT']}/config/environment.rb" config = Bivouac::Environment.new( ) database_connection = config.environment.db if database_connection[:adapter] =~ /sqlite/ database_connection[:database] = ENV['BIVOUAC_ROOT'] + "/" + database_connection[:database] end BivouacSample::Models::Base.establish_connection database_connection end namespace :db do desc "Migrate the database through scripts in db/migrate." task :migrate => :environment do if BivouacSample.respond_to? :create BivouacSample.create else puts "Nothing to do!" end end desc "Clear the sessions table" namespace :sessions do task :clear => :environment do session_table = 'session' session_table = Inflector.pluralize(session_table) if ActiveRecord::Base.pluralize_table_names ActiveRecord::Base.connection.execute "DELETE FROM #{session_table}" end end end