Started initial idea for automated database configuration

master
Sam Lown 2011-04-14 00:46:55 +02:00
parent d62c2d1439
commit 37c021a6b9
2 changed files with 19 additions and 0 deletions

View File

@ -11,11 +11,13 @@ module CouchRest
add_config :model_type_key
add_config :mass_assign_any_attribute
add_config :auto_update_design_doc
add_config :database_config_path
configure do |config|
config.model_type_key = 'model' # was 'couchrest-type'
config.mass_assign_any_attribute = false
config.auto_update_design_doc = true
config.database_config_path = File.join(defined?(Rails) ? Rails.root : Dir.pwd, 'config', 'couchdb.yml')
end
end

View File

@ -89,6 +89,9 @@ module CouchRest
self
end
def database
self.class.database(@database)
end
protected
@ -105,6 +108,20 @@ module CouchRest
module ClassMethods
# Replace CouchRest's database reader with a more advanced
# version that will make a best guess at the database you might
# want to use. Allows for a string to be provided instead of
# a database object.
def database(db = nil)
db ||= @database
if db.nil?
# try to grab from configuration files
else
db
end
end
# Creates a new instance, bypassing attribute protection
#
# ==== Returns