diff --git a/lib/couchbase/management/scope_search_index_manager.rb b/lib/couchbase/management/scope_search_index_manager.rb index da3c1ded..a31ab1e7 100644 --- a/lib/couchbase/management/scope_search_index_manager.rb +++ b/lib/couchbase/management/scope_search_index_manager.rb @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +require_relative "search_index_manager" + module Couchbase module Management class ScopeSearchIndexManager @@ -31,23 +33,23 @@ def initialize(backend, bucket_name, scope_name) # Fetches an index from the server if it exists # # @param [String] index_name name of the index - # @param [GetIndexOptions] options + # @param [Options::Search::GetIndex] options # # @return [SearchIndex] # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def get_index(index_name, options = GetIndexOptions.new) + def get_index(index_name, options = Options::Search::GetIndex::DEFAULT) res = @backend.search_index_get(@bucket_name, @scope_name, index_name, options.timeout) SearchIndexManager.extract_search_index(res) end # Fetches all indexes from the server # - # @param [GetAllIndexesOptions] options + # @param [Options::Search::GetAllIndexes] options # # @return [Array] - def get_all_indexes(options = GetAllIndexesOptions.new) + def get_all_indexes(options = Options::Search::GetAllIndexes::DEFAULT) res = @backend.search_index_get_all(@bucket_name, @scope_name, options.timeout) res[:indexes].map { |idx| SearchIndexManager.extract_search_index(idx) } end @@ -55,38 +57,38 @@ def get_all_indexes(options = GetAllIndexesOptions.new) # Creates or updates the index # # @param [SearchIndex] index_definition the index definition - # @param [UpsertIndexOptions] options + # @param [Options::Search::UpsertIndex] options # # @return void # # @raise [ArgumentError] if name, type or source_type is empty - def upsert_index(index_definition, options = UpsertIndexOptions.new) + def upsert_index(index_definition, options = Options::Search::UpsertIndex::DEFAULT) @backend.search_index_upsert(@bucket_name, @scope_name, index_definition.to_backend, options.timeout) end # Drops the index # # @param [String] index_name name of the index - # @param [DropIndexOptions] options + # @param [Options::Search::DropIndex] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def drop_index(index_name, options = DropIndexOptions.new) + def drop_index(index_name, options = Options::Search::DropIndex::DEFAULT) @backend.search_index_drop(@bucket_name, @scope_name, index_name, options.timeout) end # Retrieves the number of documents that have been indexed for an index # # @param [String] index_name name of the index - # @param [GetIndexedDocumentsCountOptions] options + # @param [Options::Search::GetIndexedDocumentsCount] options # # @return [Integer] # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new) + def get_indexed_documents_count(index_name, options = Options::Search::GetIndexedDocumentsCount::DEFAULT) res = @backend.search_index_get_documents_count(@bucket_name, @scope_name, index_name, options.timeout) res[:count] end @@ -94,78 +96,78 @@ def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOp # Pauses updates and maintenance for the index # # @param [String] index_name name of the index - # @param [PauseIngestOptions] options + # @param [Options::Search::PauseIngest] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def pause_ingest(index_name, options = PauseIngestOptions.new) + def pause_ingest(index_name, options = Options::Search::PauseIngest::DEFAULT) @backend.search_index_pause_ingest(@bucket_name, @scope_name, index_name, options.timeout) end # Resumes updates and maintenance for an index # # @param [String] index_name name of the index - # @param [ResumeIngestOptions] options + # @param [Options::Search::ResumeIngest] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def resume_ingest(index_name, options = ResumeIngestOptions.new) + def resume_ingest(index_name, options = Options::Search::ResumeIngest::DEFAULT) @backend.search_index_resume_ingest(@bucket_name, @scope_name, index_name, options.timeout) end # Allows querying against the index # # @param [String] index_name name of the index - # @param [AllowQueryingOptions] options + # @param [Options::Search::AllowQuerying] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def allow_querying(index_name, options = AllowQueryingOptions.new) + def allow_querying(index_name, options = Options::Search::AllowQuerying::DEFAULT) @backend.search_index_allow_querying(@bucket_name, @scope_name, index_name, options.timeout) end # Disallows querying against the index # # @param [String] index_name name of the index - # @param [DisallowQueryingOptions] options + # @param [Options::Search::DisallowQuerying] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def disallow_querying(index_name, options = DisallowQueryingOptions.new) + def disallow_querying(index_name, options = Options::Search::DisallowQuerying::DEFAULT) @backend.search_index_disallow_querying(@bucket_name, @scope_name, index_name, options.timeout) end # Freeze the assignment of index partitions to nodes # # @param [String] index_name name of the index - # @param [FreezePlanOptions] options + # @param [Options::Search::FreezePlan] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def freeze_plan(index_name, options = FreezePlanOptions.new) + def freeze_plan(index_name, options = Options::Search::FreezePlan::DEFAULT) @backend.search_index_freeze_plan(@bucket_name, @scope_name, index_name, options.timeout) end # Unfreeze the assignment of index partitions to nodes # # @param [String] index_name name of the index - # @param [UnfreezePlanOptions] options + # @param [Options::Search::UnfreezePlan] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def unfreeze_plan(index_name, options = UnfreezePlanOptions.new) + def unfreeze_plan(index_name, options = Options::Search::UnfreezePlan::DEFAULT) @backend.search_index_unfreeze_plan(@bucket_name, @scope_name, index_name, options.timeout) end @@ -173,28 +175,64 @@ def unfreeze_plan(index_name, options = UnfreezePlanOptions.new) # # @param [String] index_name name of the index # @param [Hash] document the document to be analyzed + # @param [Options::Search::AnalyzeDocument] options # # @return [Array] # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def analyze_document(index_name, document, options = AnalyzeDocumentOptions.new) + def analyze_document(index_name, document, options = Options::Search::AnalyzeDocument::DEFAULT) res = @backend.search_index_analyze_document(@bucket_name, @scope_name, index_name, JSON.generate(document), options.timeout) JSON.parse(res[:analysis]) end - GetIndexOptions = SearchIndexManager::GetIndexOptions - GetAllIndexesOptions = SearchIndexManager::GetAllIndexesOptions - UpsertIndexOptions = SearchIndexManager::UpsertIndexOptions - DropIndexOptions = SearchIndexManager::DropIndexOptions - GetIndexedDocumentsCountOptions = SearchIndexManager::GetIndexedDocumentsCountOptions - PauseIngestOptions = SearchIndexManager::PauseIngestOptions - ResumeIngestOptions = SearchIndexManager::ResumeIngestOptions - AllowQueryingOptions = SearchIndexManager::AllowQueryingOptions - DisallowQueryingOptions = SearchIndexManager::DisallowQueryingOptions - FreezePlanOptions = SearchIndexManager::FreezePlanOptions - UnfreezePlanOptions = SearchIndexManager::UnfreezePlanOptions - AnalyzeDocumentOptions = SearchIndexManager::AnalyzeDocumentOptions + # @api private + # @deprecated use {Options::Search::GetIndex} instead + GetIndexOptions = Options::Search::GetIndex + + # @api private + # @deprecated use {Options::Search::GetAllIndexes} instead + GetAllIndexesOptions = Options::Search::GetAllIndexes + + # @api private + # @deprecated use {Options::Search::UpsertIndex} instead + UpsertIndexOptions = Options::Search::UpsertIndex + + # @api private + # @deprecated use {Options::Search::DropIndex} instead + DropIndexOptions = Options::Search::DropIndex + + # @api private + # @deprecated use {Options::Search::GetIndexedDocumentsCount} instead + GetIndexedDocumentsCountOptions = Options::Search::GetIndexedDocumentsCount + + # @api private + # @deprecated use {Options::Search::PauseIngest} instead + PauseIngestOptions = Options::Search::PauseIngest + + # @api private + # @deprecated use {Options::Search::ResumeIngest} instead + ResumeIngestOptions = Options::Search::ResumeIngest + + # @api private + # @deprecated use {Options::Search::AllowQuerying} instead + AllowQueryingOptions = Options::Search::AllowQuerying + + # @api private + # @deprecated use {Options::Search::DisallowQuerying} instead + DisallowQueryingOptions = Options::Search::DisallowQuerying + + # @api private + # @deprecated use {Options::Search::FreezePlan} instead + FreezePlanOptions = Options::Search::FreezePlan + + # @api private + # @deprecated use {Options::Search::UnfreezePlan} instead + UnfreezePlanOptions = Options::Search::UnfreezePlan + + # @api private + # @deprecated use {Options::Search::AnalyzeDocument} instead + AnalyzeDocumentOptions = Options::Search::AnalyzeDocument end end end diff --git a/lib/couchbase/management/search_index_manager.rb b/lib/couchbase/management/search_index_manager.rb index d7120837..13577e74 100644 --- a/lib/couchbase/management/search_index_manager.rb +++ b/lib/couchbase/management/search_index_manager.rb @@ -15,9 +15,274 @@ # limitations under the License. require "couchbase/errors" +require "couchbase/options" module Couchbase module Management + module Options + module Search + # Options for {SearchIndexManager#get_index} + class GetIndex < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#get_index} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetIndex] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#get_all_indexes} + class GetAllIndexes < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#get_all_indexes} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetAllIndexes] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#upsert_index} + class UpsertIndex < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#upsert_index} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [UpsertIndex] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#drop_index} + class DropIndex < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#drop_index} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [DropIndex] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#get_indexed_documents_count} + class GetIndexedDocumentsCount < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#get_indexed_documents_count} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetIndexedDocumentsCount] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#get_index_stats} + class GetIndexStats < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#get_index_stats} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetIndexStats] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#pause_ingest} + class PauseIngest < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#pause_ingest} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [PauseIngest] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#resume_ingest} + class ResumeIngest < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#resume_ingest} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [ResumeIngest] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#allow_querying} + class AllowQuerying < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#allow_querying} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [AllowQuerying] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#disallow_querying} + class DisallowQuerying < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#disallow_querying} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [DisallowQuerying] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#freeze_plan} + class FreezePlan < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#freeze_plan} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [FreezePlan] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#unfreeze_plan} + class UnfreezePlan < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#unfreeze_plan} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [UnfreezePlan] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {SearchIndexManager#analyze_document} + class AnalyzeDocument < ::Couchbase::Options::Base + # Creates an instance of options for {SearchIndexManager#analyze_document} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [AnalyzeDocument] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + end + end + class SearchIndexManager alias inspect to_s @@ -29,23 +294,23 @@ def initialize(backend) # Fetches an index from the server if it exists # # @param [String] index_name name of the index - # @param [GetIndexOptions] options + # @param [Options::Search::GetIndex] options # # @return [SearchIndex] # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def get_index(index_name, options = GetIndexOptions.new) + def get_index(index_name, options = Options::Search::GetIndex::DEFAULT) res = @backend.search_index_get(nil, nil, index_name, options.timeout) self.class.extract_search_index(res) end # Fetches all indexes from the server # - # @param [GetAllIndexesOptions] options + # @param [Options::Search::GetAllIndexes] options # # @return [Array] - def get_all_indexes(options = GetAllIndexesOptions.new) + def get_all_indexes(options = Options::Search::GetAllIndexes::DEFAULT) res = @backend.search_index_get_all(nil, nil, options.timeout) res[:indexes].map { |idx| self.class.extract_search_index(idx) } end @@ -53,12 +318,12 @@ def get_all_indexes(options = GetAllIndexesOptions.new) # Creates or updates the index # # @param [SearchIndex] index_definition the index definition - # @param [UpsertIndexOptions] options + # @param [Options::Search::UpsertIndex] options # # @return void # # @raise [ArgumentError] if name, type or source_type is empty - def upsert_index(index_definition, options = UpsertIndexOptions.new) + def upsert_index(index_definition, options = Options::Search::UpsertIndex::DEFAULT) @backend.search_index_upsert( nil, nil, @@ -79,26 +344,26 @@ def upsert_index(index_definition, options = UpsertIndexOptions.new) # Drops the index # # @param [String] index_name name of the index - # @param [DropIndexOptions] options + # @param [Options::Search::DropIndex] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def drop_index(index_name, options = DropIndexOptions.new) + def drop_index(index_name, options = Options::Search::DropIndex::DEFAULT) @backend.search_index_drop(nil, nil, index_name, options.timeout) end # Retrieves the number of documents that have been indexed for an index # # @param [String] index_name name of the index - # @param [GetIndexedDocumentsCountOptions] options + # @param [Options::Search::GetIndexedDocumentsCount] options # # @return [Integer] # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new) + def get_indexed_documents_count(index_name, options = Options::Search::GetIndexedDocumentsCount::DEFAULT) res = @backend.search_index_get_documents_count(nil, nil, index_name, options.timeout) res[:count] end @@ -108,13 +373,13 @@ def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOp # @!macro uncommitted # # @param [String] index_name name of the index - # @param [GetIndexStatsOptions] options + # @param [Options::Search::GetIndexStats] options # # @return [Integer] # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def get_index_stats(index_name, options = GetIndexStatsOptions.new) + def get_index_stats(index_name, options = Options::Search::GetIndexStats::DEFAULT) res = @backend.search_index_get_stats(index_name, options.timeout) JSON.parse(res) end @@ -124,12 +389,12 @@ def get_index_stats(index_name, options = GetIndexStatsOptions.new) # # @!macro uncommitted # - # @param [GetIndexStatsOptions] options + # @param [Options::Search::GetIndexStats] options # # @return [Integer] # # @raise [ArgumentError] - def get_stats(options = GetIndexStatsOptions.new) + def get_stats(options = Options::Search::GetIndexStats::DEFAULT) res = @backend.search_get_stats(options.timeout) JSON.parse(res) end @@ -137,78 +402,78 @@ def get_stats(options = GetIndexStatsOptions.new) # Pauses updates and maintenance for the index # # @param [String] index_name name of the index - # @param [PauseIngestOptions] options + # @param [Options::Search::PauseIngest] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def pause_ingest(index_name, options = PauseIngestOptions.new) + def pause_ingest(index_name, options = Options::Search::PauseIngest::DEFAULT) @backend.search_index_pause_ingest(nil, nil, index_name, options.timeout) end # Resumes updates and maintenance for an index # # @param [String] index_name name of the index - # @param [ResumeIngestOptions] options + # @param [Options::Search::ResumeIngest] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def resume_ingest(index_name, options = ResumeIngestOptions.new) + def resume_ingest(index_name, options = Options::Search::ResumeIngest::DEFAULT) @backend.search_index_resume_ingest(nil, nil, index_name, options.timeout) end # Allows querying against the index # # @param [String] index_name name of the index - # @param [AllowQueryingOptions] options + # @param [Options::Search::AllowQuerying] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def allow_querying(index_name, options = AllowQueryingOptions.new) + def allow_querying(index_name, options = Options::Search::AllowQuerying::DEFAULT) @backend.search_index_allow_querying(nil, nil, index_name, options.timeout) end # Disallows querying against the index # # @param [String] index_name name of the index - # @param [DisallowQueryingOptions] options + # @param [Options::Search::DisallowQuerying] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def disallow_querying(index_name, options = DisallowQueryingOptions.new) + def disallow_querying(index_name, options = Options::Search::DisallowQuerying::DEFAULT) @backend.search_index_disallow_querying(nil, nil, index_name, options.timeout) end # Freeze the assignment of index partitions to nodes # # @param [String] index_name name of the index - # @param [FreezePlanOptions] options + # @param [Options::Search::FreezePlan] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def freeze_plan(index_name, options = FreezePlanOptions.new) + def freeze_plan(index_name, options = Options::Search::FreezePlan::DEFAULT) @backend.search_index_freeze_plan(nil, nil, index_name, options.timeout) end # Unfreeze the assignment of index partitions to nodes # # @param [String] index_name name of the index - # @param [UnfreezePlanOptions] options + # @param [Options::Search::UnfreezePlan] options # # @return void # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def unfreeze_plan(index_name, options = UnfreezePlanOptions.new) + def unfreeze_plan(index_name, options = Options::Search::UnfreezePlan::DEFAULT) @backend.search_index_unfreeze_plan(nil, nil, index_name, options.timeout) end @@ -216,145 +481,68 @@ def unfreeze_plan(index_name, options = UnfreezePlanOptions.new) # # @param [String] index_name name of the index # @param [Hash] document the document to be analyzed + # @param [Options::Search::AnalyzeDocument] options # # @return [Array] # # @raise [ArgumentError] # @raise [Error::IndexNotFound] - def analyze_document(index_name, document, options = AnalyzeDocumentOptions.new) + def analyze_document(index_name, document, options = Options::Search::AnalyzeDocument::DEFAULT) res = @backend.search_index_analyze_document(nil, nil, index_name, JSON.generate(document), options.timeout) JSON.parse(res[:analysis]) end - class GetIndexOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetIndexOptions] self - def initialize - yield self if block_given? - end - end - - class GetAllIndexesOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetAllIndexesOptions] self - def initialize - yield self if block_given? - end - end - - class UpsertIndexOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [UpsertIndexOptions] self - def initialize - yield self if block_given? - end - end - - class DropIndexOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [DropIndexOptions] self - def initialize - yield self if block_given? - end - end - - class GetIndexedDocumentsCountOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetIndexedDocumentCountOptions] self - def initialize - yield self if block_given? - end - end - - class GetIndexStatsOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetStatsOptions] self - def initialize - yield self if block_given? - end - end - - class PauseIngestOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [PauseIngestOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::Search::GetIndex} instead + GetIndexOptions = Options::Search::GetIndex - class ResumeIngestOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::Search::GetAllIndexes} instead + GetAllIndexesOptions = Options::Search::GetAllIndexes - # @yieldparam [ResumeIngestOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::Search::UpsertIndex} instead + UpsertIndexOptions = Options::Search::UpsertIndex - class AllowQueryingOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::Search::DropIndex} instead + DropIndexOptions = Options::Search::DropIndex - # @yieldparam [AllowQueryingOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::Search::GetIndexedDocumentsCount} instead + GetIndexedDocumentsCountOptions = Options::Search::GetIndexedDocumentsCount - class DisallowQueryingOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::Search::GetIndexStats} instead + GetIndexStatsOptions = Options::Search::GetIndexStats - # @yieldparam [DisallowQueryingOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::Search::PauseIngest} instead + PauseIngestOptions = Options::Search::PauseIngest - class FreezePlanOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::Search::ResumeIngest} instead + ResumeIngestOptions = Options::Search::ResumeIngest - # @yieldparam [FreezePlanOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::Search::AllowQuerying} instead + AllowQueryingOptions = Options::Search::AllowQuerying - class UnfreezePlanOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::Search::DisallowQuerying} instead + DisallowQueryingOptions = Options::Search::DisallowQuerying - # @yieldparam [UnfreezePlanOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::Search::FreezePlan} instead + FreezePlanOptions = Options::Search::FreezePlan - class AnalyzeDocumentOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::Search::UnfreezePlan} instead + UnfreezePlanOptions = Options::Search::UnfreezePlan - # @yieldparam [AnalyzeDocumentOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::Search::AnalyzeDocument} instead + AnalyzeDocumentOptions = Options::Search::AnalyzeDocument # @api private def self.extract_search_index(resp) diff --git a/lib/couchbase/management/user_manager.rb b/lib/couchbase/management/user_manager.rb index 2db70814..bbf52123 100644 --- a/lib/couchbase/management/user_manager.rb +++ b/lib/couchbase/management/user_manager.rb @@ -15,11 +15,227 @@ # limitations under the License. require "couchbase/errors" +require "couchbase/options" require "time" module Couchbase module Management + module Options + module User + # Options for {UserManager#get_user} + class GetUser < ::Couchbase::Options::Base + # @return [:local, :external] Name of the user's domain. Defaults to +:local+ + attr_accessor :domain + + # Creates an instance of options for {UserManager#get_user} + # @param [:local, :external] domain the name of the user's domain. Defaults to +:local+ + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetUser] self + def initialize(domain: :local, + timeout: nil, + retry_strategy: nil, + parent_span: nil) + super(timeout: timeout, retry_strategy: retry_strategy, parent_span: parent_span) + @domain = domain + yield self if block_given? + end + + # @api private + DEFAULT = GetUser.new.freeze + end + + # Options for {UserManager#get_all_users} + class GetAllUsers < ::Couchbase::Options::Base + # @return [:local, :external] Name of the user's domain. Defaults to +:local+ + attr_accessor :domain + + # Creates an instance of options for {UserManager#get_all_users} + # @param [:local, :external] the name of the user's domain. Defaults to +:local+ + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetAllUsers] self + def initialize(domain: :local, + timeout: nil, + retry_strategy: nil, + parent_span: nil) + super(timeout: timeout, retry_strategy: retry_strategy, parent_span: parent_span) + @domain = domain + yield self if block_given? + end + end + + # Options for {UserManager#upsert_user} + class UpsertUser < ::Couchbase::Options::Base + # @return [:local, :external] Name of the user's domain. Defaults to +:local+ + attr_accessor :domain + + # Creates an instance of options for {UserManager#upsert_user} + # @param [:local, :external] domain the name of the user's domain. Defaults to +:local+ + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [UpsertUser] self + def initialize(domain: :local, + timeout: nil, + retry_strategy: nil, + parent_span: nil) + super(timeout: timeout, retry_strategy: retry_strategy, parent_span: parent_span) + @domain = domain + yield self if block_given? + end + + # @api private + DEFAULT = UpsertUser.new.freeze + end + + # Options for {UserManager#drop_user} + class DropUser < ::Couchbase::Options::Base + # @return [:local, :external] Name of the user's domain. Defaults to +:local+ + attr_accessor :domain + + # Creates an instance of options for {UserManager#drop_user} + # @param [:local, :external] domain the name of the user's domain. Defaults to +:local+ + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [DropUser] self + def initialize(domain: :local, + timeout: nil, + retry_strategy: nil, + parent_span: nil) + super(timeout: timeout, retry_strategy: retry_strategy, parent_span: parent_span) + @domain = domain + yield self if block_given? + end + + # @api private + DEFAULT = DropUser.new.freeze + end + + # Options for {UserManager#change_password} + class ChangePassword < ::Couchbase::Options::Base + # Creates an instance of options for {UserManager#change_password} + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [ChangePassword] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = ChangePassword.new.freeze + end + + # Options for {UserManager#get_roles} + class GetRoles < ::Couchbase::Options::Base + # Creates an instance of options for {UserManager#get_roles} + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetRoles] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = GetRoles.new.freeze + end + + # Options for {UserManager#get_group} + class GetGroup < ::Couchbase::Options::Base + # Creates an instance of options for {UserManager#get_group} + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetGroup] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = GetGroup.new.freeze + end + + # Options for {UserManager#get_all_groups} + class GetAllGroups < ::Couchbase::Options::Base + # Creates an instance of options for {UserManager#get_all_groups} + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetAllGroups] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = GetAllGroups.new.freeze + end + + # Options for {UserManager#upsert_group} + class UpsertGroup < ::Couchbase::Options::Base + # Creates an instance of options for {UserManager#upsert_group} + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [UpsertGroup] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = UpsertGroup.new.freeze + end + + # Options for {UserManager#drop_group} + class DropGroup < ::Couchbase::Options::Base + # Creates an instance of options for {UserManager#drop_group} + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [DropGroup] self + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = DropGroup.new.freeze + end + end + end + class UserManager alias inspect to_s @@ -31,21 +247,23 @@ def initialize(backend) # Get a user # # @param [String] username ID of the user - # @param [GetUserOptions] options + # @param [Options::User::GetUser] options # # @return [UserAndMetadata] # # @raise [ArgumentError] # @raise [Error::UserNotFound] - def get_user(username, options = GetUserOptions.new) + def get_user(username, options = Options::User::GetUser::DEFAULT) resp = @backend.user_get(options.domain, username, options.timeout) extract_user(resp) end # Gets all users # + # @param [Options::User::GetAllUsers] options + # # @return [Array] - def get_all_users(options = GetAllUsersOptions.new) + def get_all_users(options = Options::User::GetAllUsers::DEFAULT) resp = @backend.user_get_all(options.domain, options.timeout) resp.map { |entry| extract_user(entry) } end @@ -53,10 +271,10 @@ def get_all_users(options = GetAllUsersOptions.new) # Creates or updates a user # # @param [User] user the new version of the user - # @param [UpsertUserOptions] options + # @param [Options::User::UpsertUser] options # # @raise [ArgumentError] - def upsert_user(user, options = UpsertUserOptions.new) + def upsert_user(user, options = Options::User::UpsertUser::DEFAULT) @backend.user_upsert( options.domain, { @@ -79,17 +297,17 @@ def upsert_user(user, options = UpsertUserOptions.new) # Removes a user # # @param [String] username ID of the user - # @param [DropUserOptions] options - def drop_user(username, options = DropUserOptions.new) + # @param [Options::User::DropUser] options + def drop_user(username, options = Options::User::DropUser::DEFAULT) @backend.user_drop(options.domain, username, options.timeout) end # Gets all roles supported by the server # - # @param [GetRolesOptions] options + # @param [Options::User::GetRoles] options # # @return [Array] - def get_roles(options = GetRolesOptions.new) + def get_roles(options = Options::User::GetRoles::DEFAULT) resp = @backend.role_get_all(options.timeout) resp.map do |r| RoleAndDescription.new do |role| @@ -105,32 +323,33 @@ def get_roles(options = GetRolesOptions.new) # Changes the password of the currently authenticated user # - # @param [ChangePasswordOptions] options + # @param [Options::User::ChangePassword] options # # @raise [ArgumentError] - def change_password(new_password, options = ChangePasswordOptions.new) + def change_password(new_password, options = Options::User::ChangePassword::DEFAULT) @backend.change_password(new_password, options.timeout) end # Gets a group # # @param [String] group_name name of the group to get + # @param [Options::User::GetGroup] options # # @return [Group] # # @raise [ArgumentError] # @raise [Error::GroupNotFound] - def get_group(group_name, options = GetGroupOptions.new) + def get_group(group_name, options = Options::User::GetGroup::DEFAULT) resp = @backend.group_get(group_name, options.timeout) extract_group(resp) end # Gets all groups # - # @param [GetAllGroupsOptions] options + # @param [Options::User::GetAllGroups] options # # @return [Array] - def get_all_groups(options = GetAllGroupsOptions.new) + def get_all_groups(options = Options::User::GetAllGroups::DEFAULT) resp = @backend.group_get_all(options.timeout) resp.map { |entry| extract_group(entry) } end @@ -138,11 +357,11 @@ def get_all_groups(options = GetAllGroupsOptions.new) # Creates or updates a group # # @param [Group] group the new version of the group - # @param [UpsertGroupOptions] options + # @param [Options::User::UpsertGroup] options # # @raise [ArgumentError] # @raise [Error::GroupNotFound] - def upsert_group(group, options = UpsertGroupOptions.new) + def upsert_group(group, options = Options::User::UpsertGroup::DEFAULT) @backend.group_upsert({ name: group.name, description: group.description, @@ -161,128 +380,52 @@ def upsert_group(group, options = UpsertGroupOptions.new) # Removes a group # # @param [String] group_name name of the group - # @param [DropGroupOptions] options + # @param [Options::User::DropGroup] options # # @raise [Error::GroupNotFound] - def drop_group(group_name, options = DropGroupOptions.new) + def drop_group(group_name, options = Options::User::DropGroup::DEFAULT) @backend.group_drop(group_name, options.timeout) end - class GetUserOptions - # @return [:local, :external] Name of the user's domain. Defaults to +:local+ - attr_accessor :domain - - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetUserOptions] self - def initialize - @domain = :local - yield self if block_given? - end - end - - class GetAllUsersOptions - # @return [:local, :external] Name of the user's domain. Defaults to +:local+ - attr_accessor :domain - - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetAllUsersOptions] self - def initialize - @domain = :local - yield self if block_given? - end - end - - class UpsertUserOptions - # @return [:local, :external] Name of the user's domain. Defaults to +:local+ - attr_accessor :domain - - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [UpsertUserOptions] self - def initialize - @domain = :local - yield self if block_given? - end - end - - class DropUserOptions - # @return [:local, :external] Name of the user's domain. Defaults to +:local+ - attr_accessor :domain + # @api private + # @deprecated Use {Couchbase::Management::Options::User::GetUser} instead + GetUserOptions = ::Couchbase::Management::Options::User::GetUser - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated Use {Couchbase::Management::Options::User::GetAllUsers} instead + GetAllUsersOptions = ::Couchbase::Management::Options::User::GetAllUsers - # @yieldparam [DropUserOptions] self - def initialize - @domain = :local - yield self if block_given? - end - end - - class ChangePasswordOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated Use {Couchbase::Management::Options::User::UpsertUser} instead + UpsertUserOptions = ::Couchbase::Management::Options::User::UpsertUser - # @yieldparam [ChangePasswordOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated Use {Couchbase::Management::Options::User::DropUser} instead + DropUserOptions = ::Couchbase::Management::Options::User::DropUser - class GetRolesOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated Use {Couchbase::Management::Options::User::ChangePassword} instead + ChangePasswordOptions = ::Couchbase::Management::Options::User::ChangePassword - # @yieldparam [GetRolesOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated Use {Couchbase::Management::Options::User::GetRoles} instead + GetRolesOptions = ::Couchbase::Management::Options::User::GetRoles - class GetGroupOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated Use {Couchbase::Management::Options::User::GetGroup} instead + GetGroupOptions = ::Couchbase::Management::Options::User::GetGroup - # @yieldparam [GetGroupOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated Use {Couchbase::Management::Options::User::GetAllGroups} instead + GetAllGroupsOptions = ::Couchbase::Management::Options::User::GetAllGroups - class GetAllGroupsOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated Use {Couchbase::Management::Options::User::UpsertGroup} instead + UpsertGroupOptions = ::Couchbase::Management::Options::User::UpsertGroup - # @yieldparam [GetAllGroupsOptions] self - def initialize - yield self if block_given? - end - end - - class UpsertGroupOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [UpsertGroupOptions] self - def initialize - yield self if block_given? - end - end - - class DropGroupOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [DropGroupOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated Use {Couchbase::Management::Options::User::DropGroup} instead + DropGroupOptions = ::Couchbase::Management::Options::User::DropGroup private diff --git a/lib/couchbase/management/view_index_manager.rb b/lib/couchbase/management/view_index_manager.rb index cf6a6dd8..1b11ccf3 100644 --- a/lib/couchbase/management/view_index_manager.rb +++ b/lib/couchbase/management/view_index_manager.rb @@ -15,9 +15,114 @@ # limitations under the License. require "couchbase/errors" +require "couchbase/options" module Couchbase module Management + module Options + module View + # Options for {ViewIndexManager#get_design_document} + class GetDesignDocument < Couchbase::Options::Base + # Creates an instance of options for {ViewIndexManager#get_design_document} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetDesignDocument] + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {ViewIndexManager#get_all_design_documents} + class GetAllDesignDocuments < Couchbase::Options::Base + # Creates an instance of options for {ViewIndexManager#get_all_design_documents} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [GetAllDesignDocuments] + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {ViewIndexManager#upsert_design_document} + class UpsertDesignDocument < Couchbase::Options::Base + # Creates an instance of options for {ViewIndexManager#upsert_design_document} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [UpsertDesignDocument] + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {ViewIndexManager#drop_design_document} + class DropDesignDocument < Couchbase::Options::Base + # Creates an instance of options for {ViewIndexManager#drop_design_document} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [DropDesignDocument] + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + + # Options for {ViewIndexManager#publish_design_document} + class PublishDesignDocument < Couchbase::Options::Base + # Creates an instance of options for {ViewIndexManager#publish_design_document} + # + # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete + # @param [Proc, nil] retry_strategy the custom retry strategy, if set + # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request + # + # @yieldparam [PublishDesignDocument] + def initialize(timeout: nil, + retry_strategy: nil, + parent_span: nil) + super + yield self if block_given? + end + + # @api private + DEFAULT = new.freeze + end + end + end + # 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 @@ -50,12 +155,12 @@ def initialize(backend, bucket_name) # # @param [String] name the name of the design document # @param [:production, :development] namespace the namespace - # @param [GetDesignDocumentOptions] options + # @param [Options::View::GetDesignDocument] options # # @return [DesignDocument] # # @raise [Error::DesignDocumentNotFound] - def get_design_document(name, namespace, options = GetDesignDocumentOptions.new) + def get_design_document(name, namespace, options = Options::View::GetDesignDocument::DEFAULT) resp = @backend.view_index_get(@bucket_name, name, namespace, options.timeout) extract_design_document(resp) end @@ -63,10 +168,10 @@ def get_design_document(name, namespace, options = GetDesignDocumentOptions.new) # Fetches all design documents from the server # # @param [:production, :development] namespace the namespace - # @param [GetAllDesignDocumentsOptions] options + # @param [Options::View::GetAllDesignDocuments] options # # @return [Array] - def get_all_design_documents(namespace, options = GetAllDesignDocumentsOptions.new) + def get_all_design_documents(namespace, options = Options::View::GetAllDesignDocuments::DEFAULT) resp = @backend.view_index_get_all(@bucket_name, namespace, options.timeout) resp.map do |entry| extract_design_document(entry) @@ -77,10 +182,10 @@ def get_all_design_documents(namespace, options = GetAllDesignDocumentsOptions.n # # @param [DesignDocument] document # @param [:production, :development] namespace the namespace - # @param [UpsertDesignDocumentOptions] options + # @param [Options::View::UpsertDesignDocument] options # # @return [void] - def upsert_design_document(document, namespace, options = UpsertDesignDocumentOptions.new) + def upsert_design_document(document, namespace, options = Options::View::UpsertDesignDocument::DEFAULT) @backend.view_index_upsert(@bucket_name, { name: document.name, views: document.views.map do |name, view| @@ -97,12 +202,12 @@ def upsert_design_document(document, namespace, options = UpsertDesignDocumentOp # # @param [String] name design document name # @param [:production, :development] namespace the namespace - # @param [DropDesignDocumentOptions] options + # @param [Options::View::DropDesignDocument] options # # @return [void] # # @raise [Error::DesignDocumentNotFound] - def drop_design_document(name, namespace, options = DropDesignDocumentOptions.new) + def drop_design_document(name, namespace, options = Options::View::DropDesignDocument::DEFAULT) @backend.view_index_drop(@bucket_name, name, namespace, options.timeout) end @@ -112,66 +217,36 @@ def drop_design_document(name, namespace, options = DropDesignDocumentOptions.ne # it to the production namespace. # # @param [String] name design document name - # @param [PublishDesignDocumentOptions] options + # @param [Options::View::PublishDesignDocument] options # # @return [void] # # @raise [ArgumentError] # @raise [Error::DesignDocumentNotFound] - 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 - - class GetDesignDocumentOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetDesignDocumentOptions] self - def initialize - yield self if block_given? - end - end - - class GetAllDesignDocumentsOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout - - # @yieldparam [GetAllDesignDocumentsOptions] self - def initialize - yield self if block_given? - end + def publish_design_document(name, options = Options::View::PublishDesignDocument::DEFAULT) + document = get_design_document(name, :development, Options::View::GetDesignDocument.new(timeout: options.timeout)) + upsert_design_document(document, :production, Options::View::UpsertDesignDocument.new(timeout: options.timeout)) end - class UpsertDesignDocumentOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::View::GetDesignDocument} instead + GetDesignDocumentOptions = Options::View::GetDesignDocument - # @yieldparam [UpsertDesignDocumentOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::View::GetAllDesignDocuments} instead + GetAllDesignDocumentsOptions = Options::View::GetAllDesignDocuments - class DropDesignDocumentOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::View::UpsertDesignDocument} instead + UpsertDesignDocumentOptions = Options::View::UpsertDesignDocument - # @yieldparam [DropDesignDocumentOptions] self - def initialize - yield self if block_given? - end - end - - class PublishDesignDocumentOptions - # @return [Integer] the time in milliseconds allowed for the operation to complete - attr_accessor :timeout + # @api private + # @deprecated use {Options::View::DropDesignDocument} instead + DropDesignDocumentOptions = Options::View::DropDesignDocument - # @yieldparam [PublishDesignDocumentOptions] self - def initialize - yield self if block_given? - end - end + # @api private + # @deprecated use {Options::View::PublishDesignDocument} instead + PublishDesignDocumentOptions = Options::View::PublishDesignDocument private