forked from acaprojects/couchbase-orm
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unhardcode host config & use yml file
- Loading branch information
1 parent
de0ef2e
commit eed7f40
Showing
4 changed files
with
45 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
|
||
require 'couchbase' | ||
|
||
module CouchbaseOrm | ||
class Connection | ||
@options = {} | ||
class << self | ||
attr_accessor :options | ||
|
||
def self.config | ||
@@config || raise('Missing CouchbaseOrm connection config') | ||
end | ||
|
||
def self.config=(config) | ||
@@config = config | ||
end | ||
|
||
def self.cluster | ||
@cluster ||= begin | ||
options = Couchbase::Cluster::ClusterOptions.new | ||
options.authenticate(ENV["COUCHBASE_USER"], ENV["COUCHBASE_PASSWORD"]) | ||
cluster = Couchbase::Cluster.connect('couchbase://127.0.0.1', options) | ||
end | ||
cb_config = Couchbase::Configuration.new | ||
cb_config.connection_string = config[:connection_string] || raise('Missing CouchbaseOrm connection string') | ||
cb_config.username = config[:username] || raise('Missing CouchbaseOrm username') | ||
cb_config.password = config[:password] || raise('Missing CouchbaseOrm password') | ||
Couchbase::Cluster.connect(cb_config) | ||
end | ||
end | ||
|
||
def self.bucket | ||
@bucket ||= cluster.bucket(ENV["COUCHBASE_BUCKET"]) | ||
@bucket ||= begin | ||
bucket_name = config[:bucket] || raise('Missing CouchbaseOrm bucket name') | ||
cluster.bucket(bucket_name) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters