From 601c3215d925739d40859d63de3e88b0afbbe2c4 Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:06:30 +0100 Subject: [PATCH] Rename module Model to Models --- lib/meilisearch/client.rb | 6 +- lib/meilisearch/index.rb | 80 ++++++++++++------------ lib/meilisearch/models/task.rb | 2 +- spec/meilisearch/index/documents_spec.rb | 4 +- spec/meilisearch/models/task_spec.rb | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/meilisearch/client.rb b/lib/meilisearch/client.rb index eb6f5b3d..5066c04e 100644 --- a/lib/meilisearch/client.rb +++ b/lib/meilisearch/client.rb @@ -17,7 +17,7 @@ def swap_indexes(*options) mapped_array = options.map { |arr| { indexes: arr } } response = http_post '/swap-indexes', mapped_array - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end def indexes(options = {}) @@ -38,7 +38,7 @@ def create_index(index_uid, options = {}) response = http_post '/indexes', body - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end # Synchronous version of create_index. @@ -126,7 +126,7 @@ def stats def create_dump response = http_post '/dumps' - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### TASKS diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 1403d6a6..ceb96fbc 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -31,14 +31,14 @@ def fetch_raw_info def update(body) response = http_patch indexes_path(id: @uid), Utils.transform_attributes(body) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias update_index update def delete response = http_delete indexes_path(id: @uid) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias delete_index delete @@ -90,7 +90,7 @@ def add_documents(documents, primary_key = nil) documents = [documents] if documents.is_a?(Hash) response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias replace_documents add_documents alias add_or_replace_documents add_documents @@ -110,7 +110,7 @@ def add_documents_json(documents, primary_key = nil) options = { convert_body?: false } response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias replace_documents_json add_documents_json alias add_or_replace_documents_json add_documents_json @@ -119,7 +119,7 @@ def add_documents_ndjson(documents, primary_key = nil) options = { headers: { 'Content-Type' => 'application/x-ndjson' }, convert_body?: false } response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias replace_documents_ndjson add_documents_ndjson alias add_or_replace_documents_ndjson add_documents_ndjson @@ -132,7 +132,7 @@ def add_documents_csv(documents, primary_key = nil, delimiter = nil) csvDelimiter: delimiter }.compact, options - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias replace_documents_csv add_documents_csv alias add_or_replace_documents_csv add_documents_csv @@ -141,7 +141,7 @@ def update_documents(documents, primary_key = nil) documents = [documents] if documents.is_a?(Hash) response = http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias add_or_update_documents update_documents @@ -204,7 +204,7 @@ def delete_documents(options = {}) http_post "/indexes/#{@uid}/documents/delete-batch", options end - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end end alias delete_multiple_documents delete_documents @@ -223,7 +223,7 @@ def delete_document(document_id) encode_document = URI.encode_www_form_component(document_id) response = http_delete "/indexes/#{@uid}/documents/#{encode_document}" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias delete_one_document delete_document @@ -239,7 +239,7 @@ def delete_document!(document_id) def delete_all_documents response = http_delete "/indexes/#{@uid}/documents" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end def delete_all_documents! @@ -322,13 +322,13 @@ def settings def update_settings(settings) response = http_patch "/indexes/#{@uid}/settings", Utils.transform_attributes(settings) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias settings= update_settings def reset_settings response = http_delete "/indexes/#{@uid}/settings" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - RANKING RULES @@ -340,13 +340,13 @@ def ranking_rules def update_ranking_rules(ranking_rules) response = http_put "/indexes/#{@uid}/settings/ranking-rules", ranking_rules - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias ranking_rules= update_ranking_rules def reset_ranking_rules response = http_delete "/indexes/#{@uid}/settings/ranking-rules" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - SYNONYMS @@ -358,13 +358,13 @@ def synonyms def update_synonyms(synonyms) response = http_put "/indexes/#{@uid}/settings/synonyms", synonyms - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias synonyms= update_synonyms def reset_synonyms response = http_delete "/indexes/#{@uid}/settings/synonyms" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - STOP-WORDS @@ -377,13 +377,13 @@ def stop_words def update_stop_words(stop_words) body = stop_words.nil? || stop_words.is_a?(Array) ? stop_words : [stop_words] response = http_put "/indexes/#{@uid}/settings/stop-words", body - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias stop_words= update_stop_words def reset_stop_words response = http_delete "/indexes/#{@uid}/settings/stop-words" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - DINSTINCT ATTRIBUTE @@ -395,13 +395,13 @@ def distinct_attribute def update_distinct_attribute(distinct_attribute) response = http_put "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias distinct_attribute= update_distinct_attribute def reset_distinct_attribute response = http_delete "/indexes/#{@uid}/settings/distinct-attribute" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - SEARCHABLE ATTRIBUTES @@ -413,13 +413,13 @@ def searchable_attributes def update_searchable_attributes(searchable_attributes) response = http_put "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias searchable_attributes= update_searchable_attributes def reset_searchable_attributes response = http_delete "/indexes/#{@uid}/settings/searchable-attributes" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - DISPLAYED ATTRIBUTES @@ -431,13 +431,13 @@ def displayed_attributes def update_displayed_attributes(displayed_attributes) response = http_put "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias displayed_attributes= update_displayed_attributes def reset_displayed_attributes response = http_delete "/indexes/#{@uid}/settings/displayed-attributes" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - FILTERABLE ATTRIBUTES @@ -449,13 +449,13 @@ def filterable_attributes def update_filterable_attributes(filterable_attributes) response = http_put "/indexes/#{@uid}/settings/filterable-attributes", filterable_attributes - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias filterable_attributes= update_filterable_attributes def reset_filterable_attributes response = http_delete "/indexes/#{@uid}/settings/filterable-attributes" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - SORTABLE ATTRIBUTES @@ -467,13 +467,13 @@ def sortable_attributes def update_sortable_attributes(sortable_attributes) response = http_put "/indexes/#{@uid}/settings/sortable-attributes", sortable_attributes - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias sortable_attributes= update_sortable_attributes def reset_sortable_attributes response = http_delete "/indexes/#{@uid}/settings/sortable-attributes" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - PAGINATION @@ -485,13 +485,13 @@ def pagination def update_pagination(pagination) response = http_patch "/indexes/#{@uid}/settings/pagination", pagination - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias pagination= update_sortable_attributes def reset_pagination response = http_delete "/indexes/#{@uid}/settings/pagination" - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end def typo_tolerance @@ -502,13 +502,13 @@ def typo_tolerance def update_typo_tolerance(typo_tolerance_attributes) attributes = Utils.transform_attributes(typo_tolerance_attributes) response = http_patch("/indexes/#{@uid}/settings/typo-tolerance", attributes) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias typo_tolerance= update_typo_tolerance def reset_typo_tolerance response = http_delete("/indexes/#{@uid}/settings/typo-tolerance") - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end def faceting @@ -519,13 +519,13 @@ def faceting def update_faceting(faceting_attributes) attributes = Utils.transform_attributes(faceting_attributes) response = http_patch("/indexes/#{@uid}/settings/faceting", attributes) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end alias faceting= update_faceting def reset_faceting response = http_delete("/indexes/#{@uid}/settings/faceting") - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - DICTIONARY @@ -537,12 +537,12 @@ def dictionary def update_dictionary(dictionary_attributes) attributes = Utils.transform_attributes(dictionary_attributes) response = http_put("/indexes/#{@uid}/settings/dictionary", attributes) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end def reset_dictionary response = http_delete("/indexes/#{@uid}/settings/dictionary") - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - SEPARATOR TOKENS @@ -553,12 +553,12 @@ def separator_tokens def update_separator_tokens(separator_tokens_attributes) attributes = Utils.transform_attributes(separator_tokens_attributes) response = http_put("/indexes/#{@uid}/settings/separator-tokens", attributes) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end def reset_separator_tokens response = http_delete("/indexes/#{@uid}/settings/separator-tokens") - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end ### SETTINGS - NON SEPARATOR TOKENS @@ -570,12 +570,12 @@ def non_separator_tokens def update_non_separator_tokens(non_separator_tokens_attributes) attributes = Utils.transform_attributes(non_separator_tokens_attributes) response = http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes) - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end def reset_non_separator_tokens response = http_delete("/indexes/#{@uid}/settings/non-separator-tokens") - Model::Task.new(response, task_endpoint) + Models::Task.new(response, task_endpoint) end end end diff --git a/lib/meilisearch/models/task.rb b/lib/meilisearch/models/task.rb index 4a17516a..2aab0837 100644 --- a/lib/meilisearch/models/task.rb +++ b/lib/meilisearch/models/task.rb @@ -3,7 +3,7 @@ require 'forwardable' module MeiliSearch - module Model + module Models class Task extend Forwardable diff --git a/spec/meilisearch/index/documents_spec.rb b/spec/meilisearch/index/documents_spec.rb index 0d05449f..177af894 100644 --- a/spec/meilisearch/index/documents_spec.rb +++ b/spec/meilisearch/index/documents_spec.rb @@ -121,8 +121,8 @@ it 'adds documents in a batch (as a array of documents)' do tasks = index.add_documents_in_batches(documents, 5) - expect(tasks).to contain_exactly(a_kind_of(MeiliSearch::Model::Task), - a_kind_of(MeiliSearch::Model::Task)) + expect(tasks).to contain_exactly(a_kind_of(MeiliSearch::Models::Task), + a_kind_of(MeiliSearch::Models::Task)) tasks.each(&:await) expect(index.documents['results']).to contain_exactly(*documents_with_string_keys) end diff --git a/spec/meilisearch/models/task_spec.rb b/spec/meilisearch/models/task_spec.rb index 3138b479..eac6ea6c 100644 --- a/spec/meilisearch/models/task_spec.rb +++ b/spec/meilisearch/models/task_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe MeiliSearch::Model::Task do +describe MeiliSearch::Models::Task do let(:new_index_uid) { random_uid } let(:task_hash) { client.http_post '/indexes', { 'uid' => new_index_uid } } let(:endpoint) { MeiliSearch::Task.new(URL, MASTER_KEY, client.options) }