Class: CouchbaseOrm::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase-orm/connection.rb

Constant Summary collapse

@@config =
nil

Class Method Summary collapse

Class Method Details

.bucketObject



33
34
35
36
37
38
# File 'lib/couchbase-orm/connection.rb', line 33

def self.bucket
  @bucket ||= begin
    bucket_name = config[:bucket].presence || raise(CouchbaseOrm::Error.new('Missing CouchbaseOrm bucket name'))
    cluster.bucket(bucket_name)
  end
end

.clusterObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/couchbase-orm/connection.rb', line 21

def self.cluster
  @cluster ||= begin
    cb_config = Couchbase::Configuration.new
    cb_config.connection_string = config[:connection_string].presence.try { |s|
      "couchbase://#{s}"
    } || raise(CouchbaseOrm::Error.new('Missing CouchbaseOrm host'))
    cb_config.username = config[:username].presence || raise(CouchbaseOrm::Error.new('Missing CouchbaseOrm username'))
    cb_config.password = config[:password].presence || raise(CouchbaseOrm::Error.new('Missing CouchbaseOrm password'))
    Couchbase::Cluster.connect(cb_config)
  end
end

.configObject



8
9
10
11
12
13
14
15
# File 'lib/couchbase-orm/connection.rb', line 8

def self.config
  @@config || {
    connection_string: ENV['COUCHBASE_HOST'] || '127.0.0.1',
    username: ENV['COUCHBASE_USER'],
    password: ENV['COUCHBASE_PASSWORD'],
    bucket: ENV['COUCHBASE_BUCKET']
  }
end

.config=(config) ⇒ Object



17
18
19
# File 'lib/couchbase-orm/connection.rb', line 17

def self.config=(config)
  @@config = config.deep_symbolize_keys
end