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
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/couchbase/cluster.rb', line 58 def create_bucket(name, = {}) defaults = { :type => "couchbase", :ram_quota => 100, :replica_number => 1, :auth_type => "sasl", :sasl_password => "", :proxy_port => nil, :flush_enabled => false, :replica_index => true, :parallel_db_and_view_compaction => false } = 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] params["flushEnabled"] = !![:flush_enabled] params["replicaIndex"] = !![:replica_index] params["parallelDBAndViewCompaction"] = !![:parallel_db_and_view_compaction] 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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/couchbase/cluster.rb', line 102 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 |