Sha256: 5d7ad043085c22ac135631bbeed3b6865b5bfaf7445c919d12f3f4ca5e9a3be7
Contents?: true
Size: 1.98 KB
Versions: 3
Compression:
Stored size: 1.98 KB
Contents
module Lanes module DB extend self attr_accessor(:config_file) def establish_connection( env = ENV['RAILS_ENV'] || 'development') if ENV['DATABASE_URL'] ::ActiveRecord::Base.establish_connection( ENV['DATABASE_URL'] ) else file = config_file || Extensions.controlling.root_path.join("config","database.yml") config = YAML::load( IO.read(file) ) ::ActiveRecord::Base.configurations = config ::ActiveRecord::Base.establish_connection( ::ActiveRecord::Base.configurations[ env ] ) end ActiveRecord::Base.logger = Lanes.logger end def load_seed path = Pathname.new("./db/seed.rb") load path if path.exist? end def configure_rake_environment ActiveRecord::Tasks::DatabaseTasks.seed_loader = Lanes::DB default_schema = Extensions.controlling.root_path.join("db","schema.sql") env = ENV['RAILS_ENV'] || 'development' ENV['SCHEMA'] ||= default_schema.to_s ENV['DB_STRUCTURE'] ||= default_schema.to_s ActiveRecord::Base.schema_format = :sql Lanes::DB.establish_connection( env ) ActiveRecord::Tasks::DatabaseTasks.database_configuration = ActiveRecord::Base.configurations ActiveRecord::Tasks::DatabaseTasks.env = 'test' ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'db/migrate' ActiveRecord::Tasks::DatabaseTasks.current_config( :config => ActiveRecord::Base.configurations[ env ] ) end private def migrations_dir ::ActiveRecord::Migrator.migrations_paths.first end def silence_activerecord(&block) old_logger = ::ActiveRecord::Base.logger ::ActiveRecord::Base.logger = nil yield if block_given? ::ActiveRecord::Base.logger = old_logger end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lanes-0.1.8 | lib/lanes/db.rb |
lanes-0.1.7 | lib/lanes/db.rb |
lanes-0.1.6 | lib/lanes/db.rb |