use method for CouchPotato #58

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+23 −1
Split
View
@@ -28,6 +28,13 @@ def self.database
def self.couchrest_database
@@__couchrest_database ||= CouchRest.database(full_url_to_database)
end
+
+ # Returns a specific database instance
+ def self.use(database_name)
+ @@__databases ||= {}
+ @@__databases["#{database_name}"] = Database.new(couchrest_database_for_name!(database_name)) unless @@__databases["#{database_name}"]
+ @@__databases["#{database_name}"]
+ end
# Executes a block of code and yields a datbase with the given name.
#
@@ -42,10 +49,16 @@ def self.with_database(database_name)
yield(@@__databases["#{database_name}"])
end
- # Creates a CouchRest-Database for directly accessing that functionality.
+ # Returns a CouchRest-Database for directly accessing that functionality.
def self.couchrest_database_for_name(database_name)
CouchRest.database(full_url_to_database(database_name))
end
+
+ # Creates a CouchRest-Database for directly accessing that functionality.
+ def self.couchrest_database_for_name!(database_name)
+ CouchRest.database!(full_url_to_database(database_name))
+ end
+
private
@@ -19,6 +19,15 @@
end
end
+describe CouchPotato, 'use' do
+
+ it 'should return the db object' do
+ db = CouchPotato.use("testdb")
+ db.should respond_to(:load)
+ end
+
+end
+
describe CouchPotato, '.models' do
it "returns all classes that have implemented CouchPotato::Persistence" do
clazz = Class.new