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



29
30
31
32
33
34
# File 'lib/couchbase-orm/connection.rb', line 29

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

.clusterObject



19
20
21
22
23
24
25
26
27
# File 'lib/couchbase-orm/connection.rb', line 19

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')
         Couchbase::Cluster.connect(cb_config)
      end
end

.configObject



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

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

.config=(config) ⇒ Object



15
16
17
# File 'lib/couchbase-orm/connection.rb', line 15

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