Skip to content

Commit

Permalink
Merge pull request #81 from Mapotempo/fix-load-config-yaml
Browse files Browse the repository at this point in the history
fix connection with rails
  • Loading branch information
giallon committed May 28, 2024
2 parents d86aa63 + d515449 commit 5b31677
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/couchbase-orm/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ 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']
}
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
Expand Down

0 comments on commit 5b31677

Please sign in to comment.