Class: Couchbase::Management::ViewIndexManager

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

Instance Method Summary collapse

Constructor Details

#initialize(backend, bucket_name) ⇒ ViewIndexManager

Returns a new instance of ViewIndexManager.

Parameters:

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


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_nameString

Returns name of the bucket.

Returns:

  • (String)

    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

Parameters:

  • name (String)

    design document name

  • namespace (:production, :development)

    the namespace

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

Raises:



105
106
107
# File 'lib/couchbase/management/view_index_manager.rb', line 105

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:



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

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:



58
59
60
61
# File 'lib/couchbase/management/view_index_manager.rb', line 58

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:



121
122
123
124
# File 'lib/couchbase/management/view_index_manager.rb', line 121

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:



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, 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