Class: Couchbase::Cluster
- Inherits:
-
Object
- Object
- Couchbase::Cluster
- Defined in:
- lib/couchbase/cluster.rb
Instance Method Summary collapse
-
#create_bucket(name, options = {}) ⇒ Object
Create data bucket.
-
#delete_bucket(name, options = {}) ⇒ Object
Delete the data bucket.
-
#initialize(options = {}) ⇒ Cluster
constructor
Establish connection to the cluster for administration.
Constructor Details
#initialize(options = {}) ⇒ Cluster
Establish connection to the cluster for administration
30 31 32 33 34 35 |
# File 'lib/couchbase/cluster.rb', line 30 def initialize( = {}) if [:username].nil? || [:password].nil? raise ArgumentError, "username and password mandatory to connect to the cluster" end @connection = Bucket.new(.merge(:type => :cluster)) end |
Instance Method Details
#create_bucket(name, options = {}) ⇒ Object
Create data bucket
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/couchbase/cluster.rb', line 50 def create_bucket(name, = {}) defaults = { :type => "couchbase", :ram_quota => 100, :replica_number => 1, :auth_type => "sasl", :sasl_password => "", :proxy_port => nil } = defaults.merge() params = {"name" => name} params["bucketType"] = [:type] params["ramQuotaMB"] = [:ram_quota] params["replicaNumber"] = [:replica_number] params["authType"] = [:auth_type] params["saslPassword"] = [:sasl_password] params["proxyPort"] = [:proxy_port] payload = Utils.encode_params(params.reject!{|k, v| v.nil?}) request = @connection.make_http_request("/pools/default/buckets", :content_type => "application/x-www-form-urlencoded", :type => :management, :method => :post, :extended => true, :body => payload) response = nil request.on_body do |r| response = r response.instance_variable_set("@operation", :create_bucket) yield(response) if block_given? end request.continue response end |
#delete_bucket(name, options = {}) ⇒ Object
Delete the data bucket
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/couchbase/cluster.rb', line 88 def delete_bucket(name, = {}) request = @connection.make_http_request("/pools/default/buckets/#{name}", :type => :management, :method => :delete, :extended => true) response = nil request.on_body do |r| response = r response.instance_variable_set("@operation", :delete_bucket) yield(response) if block_given? end request.continue response end |