diff --git a/lib/couchbase-orm/connection.rb b/lib/couchbase-orm/connection.rb index cda9dc76..4c0dbb03 100644 --- a/lib/couchbase-orm/connection.rb +++ b/lib/couchbase-orm/connection.rb @@ -5,7 +5,7 @@ class Connection @@config = nil def self.config @@config || { - :connection_string => "couchbase://#{ENV['COUCHBASE_HOST'] || '127.0.0.1'}", + :connection_string => ENV['COUCHBASE_HOST'] || '127.0.0.1', :username => ENV['COUCHBASE_USER'], :password => ENV['COUCHBASE_PASSWORD'], :bucket => ENV['COUCHBASE_BUCKET'] @@ -13,22 +13,22 @@ def self.config end def self.config=(config) - @@config = config + @@config = config.deep_symbolize_keys end def self.cluster @cluster ||= begin cb_config = Couchbase::Configuration.new - cb_config.connection_string = config[:connection_string] || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm connection string') - cb_config.username = config[:username] || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm username') - cb_config.password = config[:password] || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm password') + cb_config.connection_string = config[:connection_string].presence.try { |s| "couchbase://#{s}" } || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm host') + cb_config.username = config[:username].presence || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm username') + cb_config.password = config[:password].presence || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm password') Couchbase::Cluster.connect(cb_config) end end def self.bucket @bucket ||= begin - bucket_name = config[:bucket] || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm bucket name') + bucket_name = config[:bucket].presence || raise(CouchbaseOrm::Error, 'Missing CouchbaseOrm bucket name') cluster.bucket(bucket_name) end end