Created
October 1, 2010 17:08
-
-
Save tizoc/606505 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ==== Database connection | |
DATABASE_URL = if File.exists?(root_path('config/database.yml')) | |
YAML.load(File.read('config/database.yml'))[RACK_ENV.to_sym] | |
end | |
if DATABASE_URL | |
DB = Sequel.connect(DATABASE_URL) | |
else | |
# Use in-memory sqlite if no db has been specified (probably running tests) | |
DB = Sequel.sqlite | |
Sequel.extension :migration | |
Sequel::Migrator.apply(DB, 'db/migrate') | |
end | |
DB.loggers << Logger.new($stdout) if monk_settings(:sequel_logging) | |
# Load optimized postgres sequel extensions if using postgres | |
if DB.adapter_scheme == :postgres | |
begin | |
require 'sequel_pg' | |
rescue LoadError | |
puts "Install the sequel_pg gem to get better performance from Sequel" | |
end | |
end | |
# ==== Sequel options | |
Sequel.extension :blank | |
Sequel.extension :pagination | |
Sequel.extension :inflector | |
Sequel::Model.plugin :subclasses | |
Sequel::Model.plugin :timestamps | |
Sequel::Model.plugin :validation_helpers | |
Sequel::Model.plugin :association_proxies | |
class Sequel::Model | |
def to_param | |
self.id.to_s | |
end | |
end | |
# ==== Undefine Sequel models (for proper reloading) | |
class Object | |
Sequel::Model.subclasses.each do |klass| | |
# Sometimes we get a klass without a name, why? | |
if klass.name && const_defined?(klass.name.to_sym) | |
klass.subclasses.each do |sklass| | |
remove_const sklass.name.to_sym if const_defined?(sklass.name.to_sym) | |
end | |
remove_const klass.name.to_sym | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment