templates/project/initialize.rb in michaelbarton-gigantron-0.1.7 vs templates/project/initialize.rb in michaelbarton-gigantron-0.1.8

- old
+ new

@@ -1,31 +1,32 @@ -# This file handles all the background initialization work that the programmer -# shouldn't have to worry about. -# This includes database startup, common requires, activesupport, and other -# magic. I'm not sure if this is a good idea or not. +require 'rubygems' +require 'activerecord' -# ENV works like in rails, except is :real or :test -GTRON_ENV rescue GTRON_ENV = :real -GTRON_ROOT = File.dirname(__FILE__) +module Gigantron + class << self + def boot(environment) + ActiveRecord::Base.establish_connection(db[environment]) -#set up autoload paths -$: << "#{GTRON_ROOT}/lib/" + ActiveRecord::Base.logger = Logger.new( + File.join(File.dirname(__FILE__),'log',"#{environment}.log")) -require 'rubygems' -require 'rake' + Dir[File.join(%W|#{File.dirname(__FILE__)} models ** *.rb |)].each {|r| + load r } + end -require 'active_record' + def migrations + File.join(File.dirname(__FILE__), 'db', 'migrate') + end -def get_db_conn(env) - env = env.to_sym - #set up logging - ActiveRecord::Base.logger = Logger.new("#{GTRON_ROOT}/log/#{env}.log") + def db + YAML::load(File.read(File.join(File.dirname(__FILE__),'database.yml'))) + end - #load in dbs from database.yml - ActiveRecord::Base.establish_connection( - YAML::load(File.read("#{GTRON_ROOT}/database.yml"))[env]) + def up!(version=nil) + ActiveRecord::Migrator.migrate migrations, version + end - #load all models - Dir["#{GTRON_ROOT}/models/**/*.rb"].each {|r| load r } - - nil + def down! + up! + end + end end