Skip to content
Browse files

use method for CouchPotato

- returns a instance to a specific db
- can be used to work with multiple databases in one project
  • Loading branch information...
1 parent d66fec5 commit 65f5e16138c4f7d1a52c02a461b7bcd233babc07 Maximilian Mack committed Mar 9, 2012
Showing with 23 additions and 1 deletion.
  1. +14 −1 lib/couch_potato.rb
  2. +9 −0 spec/unit/couch_potato_spec.rb
View
15 lib/couch_potato.rb
@@ -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
View
9 spec/unit/couch_potato_spec.rb
@@ -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

0 comments on commit 65f5e16

Please sign in to comment.
Something went wrong with that request. Please try again.