Class: Couchbase::Management::ViewIndexManager

Inherits:
Object
  • Object
show all
Defined in:
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

Instance Method Summary collapse

Constructor Details

#initialize(backend, bucket_name) ⇒ ViewIndexManager

Returns a new instance of ViewIndexManager.

Parameters:

  • backend (Couchbase::Backend)
  • bucket_name (String)


42
43
44
45
# File 'lib/couchbase/management/view_index_manager.rb', line 42

def initialize(backend, bucket_name)
  @backend = backend
  @bucket_name = bucket_name
end

Instance Attribute Details

#bucket_nameString

Returns name of the bucket.

Returns:

  • (String)

    name of the bucket



38
39
40
# File 'lib/couchbase/management/view_index_manager.rb', line 38

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

Parameters:

  • name (String)

    design document name

  • namespace (:production, :development)

    the namespace

  • options (DropDesignDocumentOptions) (defaults to: DropDesignDocumentOptions.new)

Raises:



103
104
105
# File 'lib/couchbase/management/view_index_manager.rb', line 103

def drop_design_document(name, namespace, options = DropDesignDocumentOptions.new)
  @backend.view_index_drop(@bucket_name, name, namespace, options.timeout)
end

#get_all_design_documents(namespace, options = GetAllDesignDocumentsOptions.new) ⇒ Array<DesignDocument>

Fetches all design documents from the server

Parameters:

  • namespace (:production, :development)

    the namespace

  • options (GetAllDesignDocumentsOptions) (defaults to: GetAllDesignDocumentsOptions.new)

Returns:



67
68
69
70
71
72
# File 'lib/couchbase/management/view_index_manager.rb', line 67

def get_all_design_documents(namespace, options = GetAllDesignDocumentsOptions.new)
  resp = @backend.view_index_get_all(@bucket_name, namespace, options.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

Parameters:

  • name (String)

    the name of the design document

  • namespace (:production, :development)

    the namespace

  • options (GetDesignDocumentOptions) (defaults to: GetDesignDocumentOptions.new)

Returns:

Raises:



56
57
58
59
# File 'lib/couchbase/management/view_index_manager.rb', line 56

def get_design_document(name, namespace, options = GetDesignDocumentOptions.new)
  resp = @backend.view_index_get(@bucket_name, name, namespace, options.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.

Parameters:

Raises:



119
120
121
122
# File 'lib/couchbase/management/view_index_manager.rb', line 119

def publish_design_document(name, options = PublishDesignDocumentOptions.new)
  document = get_design_document(name, :development, GetDesignDocumentOptions.new { |o| o.timeout = options.timeout })
  upsert_design_document(document, :production, UpsertDesignDocumentOptions.new { |o| o.timeout = options.timeout })
end

#upsert_design_document(document, namespace, options = UpsertDesignDocumentOptions.new) ⇒ void

This method returns an undefined value.

Updates or inserts the design document

Parameters:



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/couchbase/management/view_index_manager.rb', line 81

def upsert_design_document(document, namespace, options = 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, options.timeout)
end