Class: Couchbase::Management::ViewIndexManager
- Inherits:
-
Object
- Object
- Couchbase::Management::ViewIndexManager
- Defined in:
- lib/couchbase/management/view_index_manager.rb,
/code/couchbase-ruby-client/lib/couchbase/management/view_index_manager.rb
Overview
The View Index Manager interface contains the means for managing design documents used for views.
A design document belongs to either the “development” or “production” namespace. A development document has a name that starts with “dev_”. This is an implementation detail we’ve chosen to hide from consumers of this API. Document names presented to the user (returned from the “get” and “get all” methods, for example) always have the “dev_” prefix stripped.
Whenever the user passes a design document name to any method of this API, the user may refer to the document using the “dev_” prefix regardless of whether the user is referring to a development document or production document. The “dev_” prefix is always stripped from user input, and the actual document name passed to the server is determined by the “namespace” argument.
All methods (except publish) have a required “namespace” argument indicating whether the operation targets a development document or a production document. The type of this argument is [Symbol] with allowed values :production
and :development
.
Defined Under Namespace
Classes: DropDesignDocumentOptions, GetAllDesignDocumentsOptions, GetDesignDocumentOptions, PublishDesignDocumentOptions, UpsertDesignDocumentOptions
Instance Attribute Summary collapse
-
#bucket_name ⇒ String
Name of the bucket.
Instance Method Summary collapse
-
#drop_design_document(name, namespace, options = DropDesignDocumentOptions.new) ⇒ void
Removes the design document.
-
#get_all_design_documents(namespace, options = GetAllDesignDocumentsOptions.new) ⇒ Array<DesignDocument>
Fetches all design documents from the server.
-
#get_design_document(name, namespace, options = GetDesignDocumentOptions.new) ⇒ DesignDocument
Fetches a design document from the server.
-
#initialize(backend, bucket_name) ⇒ ViewIndexManager
constructor
A new instance of ViewIndexManager.
-
#publish_design_document(name, options = PublishDesignDocumentOptions.new) ⇒ void
Publishes the design document.
-
#upsert_design_document(document, namespace, options = UpsertDesignDocumentOptions.new) ⇒ void
Updates or inserts the design document.
Constructor Details
#initialize(backend, bucket_name) ⇒ ViewIndexManager
Returns a new instance of ViewIndexManager.
44 45 46 47 |
# File 'lib/couchbase/management/view_index_manager.rb', line 44 def initialize(backend, bucket_name) @backend = backend @bucket_name = bucket_name end |
Instance Attribute Details
#bucket_name ⇒ String
Returns name of the bucket.
40 41 42 |
# File 'lib/couchbase/management/view_index_manager.rb', line 40 def bucket_name @bucket_name end |
Instance Method Details
#drop_design_document(name, namespace, options = DropDesignDocumentOptions.new) ⇒ void
This method returns an undefined value.
Removes the design document
105 106 107 |
# File 'lib/couchbase/management/view_index_manager.rb', line 105 def drop_design_document(name, namespace, = DropDesignDocumentOptions.new) @backend.view_index_drop(@bucket_name, name, namespace, .timeout) end |
#get_all_design_documents(namespace, options = GetAllDesignDocumentsOptions.new) ⇒ Array<DesignDocument>
Fetches all design documents from the server
69 70 71 72 73 74 |
# File 'lib/couchbase/management/view_index_manager.rb', line 69 def get_all_design_documents(namespace, = GetAllDesignDocumentsOptions.new) resp = @backend.view_index_get_all(@bucket_name, namespace, .timeout) resp.map do |entry| extract_design_document(entry) end end |
#get_design_document(name, namespace, options = GetDesignDocumentOptions.new) ⇒ DesignDocument
Fetches a design document from the server
58 59 60 61 |
# File 'lib/couchbase/management/view_index_manager.rb', line 58 def get_design_document(name, namespace, = GetDesignDocumentOptions.new) resp = @backend.view_index_get(@bucket_name, name, namespace, .timeout) extract_design_document(resp) end |
#publish_design_document(name, options = PublishDesignDocumentOptions.new) ⇒ void
This method returns an undefined value.
Publishes the design document.
This method is equivalent to getting a document from the development namespace and upserting it to the production namespace.
121 122 123 124 |
# File 'lib/couchbase/management/view_index_manager.rb', line 121 def publish_design_document(name, = PublishDesignDocumentOptions.new) document = get_design_document(name, :development, GetDesignDocumentOptions.new { |o| o.timeout = .timeout }) upsert_design_document(document, :production, UpsertDesignDocumentOptions.new { |o| o.timeout = .timeout }) end |
#upsert_design_document(document, namespace, options = UpsertDesignDocumentOptions.new) ⇒ void
This method returns an undefined value.
Updates or inserts the design document
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/couchbase/management/view_index_manager.rb', line 83 def upsert_design_document(document, namespace, = UpsertDesignDocumentOptions.new) @backend.view_index_upsert(@bucket_name, { name: document.name, views: document.views.map do |name, view| { name: name, map: view.map_function, reduce: view.reduce_function, } end, }, namespace, .timeout) end |