Skip to content

Commit

Permalink
Rename module Model to Models
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix committed Nov 29, 2023
1 parent ccae3aa commit 601c321
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions lib/meilisearch/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
80 changes: 40 additions & 40 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/meilisearch/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'forwardable'

module MeiliSearch
module Model
module Models
class Task
extend Forwardable

Expand Down
4 changes: 2 additions & 2 deletions spec/meilisearch/index/documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/meilisearch/models/task_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down

0 comments on commit 601c321

Please sign in to comment.