Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

use method for CouchPotato #58

Closed
wants to merge 1 commit into from

2 participants

Max Mack Alexander Lang
Max Mack
  • returns a instance to a specific db
  • can be used to work with multiple databases in one project

The couchrest_database_for_name! method creates the database if necessary.

Any hints for better implementations?

Max Mack mmack use method for CouchPotato
- returns a instance to a specific db
- can be used to work with multiple databases in one project
65f5e16
Alexander Lang langalex closed this
Daniel Lohse annismckenzie deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2012
  1. Max Mack

    use method for CouchPotato

    mmack authored
    - returns a instance to a specific db
    - can be used to work with multiple databases in one project
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 1 deletion.
  1. +14 −1 lib/couch_potato.rb
  2. +9 −0 spec/unit/couch_potato_spec.rb
15 lib/couch_potato.rb
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
9 spec/unit/couch_potato_spec.rb
View
@@ -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
Something went wrong with that request. Please try again.