Module: CouchRest::Model::Connection::ClassMethods
- Defined in:
- lib/couchrest/model/connection.rb
Instance Method Summary collapse
-
#database ⇒ Object
Overwrite the default database method so that it always provides something from the configuration.
- #prepare_database(db = nil) ⇒ Object
- #server ⇒ Object
-
#use_database(db) ⇒ Object
Overwrite the normal use_database method so that a database name can be provided instead of a full connection.
Instance Method Details
#database ⇒ Object
Overwrite the default database method so that it always provides something from the configuration
20 21 22 |
# File 'lib/couchrest/model/connection.rb', line 20 def database super || (@database ||= prepare_database) end |
#prepare_database(db = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/couchrest/model/connection.rb', line 28 def prepare_database(db = nil) unless db.is_a?(CouchRest::Database) conf = connection_configuration db = [conf[:prefix], db.to_s, conf[:suffix]].reject{|s| s.to_s.empty?}.join(conf[:join]) self.server.database!(db) else db end end |
#server ⇒ Object
24 25 26 |
# File 'lib/couchrest/model/connection.rb', line 24 def server @server ||= CouchRest::Server.new(prepare_server_uri) end |
#use_database(db) ⇒ Object
Overwrite the normal use_database method so that a database name can be provided instead of a full connection.
14 15 16 |
# File 'lib/couchrest/model/connection.rb', line 14 def use_database(db) @database = prepare_database(db) end |