Skip to content

Commit

Permalink
Merge #498
Browse files Browse the repository at this point in the history
498: Implement new await synchronous interface r=ellnix a=ellnix

# Pull Request

## Related issue
Fixes #288

While refactoring, inadvertently fixes:
- Fixes #499
- Fixes #500

## PR checklist
Please check if your PR fulfills the following requirements:
- [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [X] Have you read the contributing guidelines?
- [X] Have you made sure that the title is accurate and descriptive of the changes?

## Changes Checklist
- [X] Add soft deprecation messages
- [X] Remove bang methods from specs
- [X] Add Task "model"
- [X] Ensure all tests pass with edits where necessary
- [X] Add tests to make sure that all bang methods actually provide deprecation warnings 
- [X] Return Task model on all methods that return tasks
  - [X] Return Task model from all settings setters and getters
- [ ] Update the documentation with new syntax (if applicable)


Co-authored-by: ellnix <103502144+ellnix@users.noreply.github.com>
  • Loading branch information
meili-bors[bot] and ellnix committed Feb 27, 2024
2 parents dcc99be + 75017dc commit 65a34c9
Show file tree
Hide file tree
Showing 29 changed files with 1,832 additions and 1,239 deletions.
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
@@ -1,21 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-01-16 21:52:52 UTC using RuboCop version 1.50.2.
# on 2024-02-16 18:01:53 UTC using RuboCop version 1.50.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 55
# Offense count: 63
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 694
Max: 581

# Offense count: 2
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 373
Max: 421

# Offense count: 1
# Configuration parameters: Max, CountKeywordArgs.
Expand Down
1 change: 1 addition & 0 deletions lib/meilisearch.rb
Expand Up @@ -2,6 +2,7 @@

require 'meilisearch/version'
require 'meilisearch/utils'
require 'meilisearch/models/task'
require 'meilisearch/http_request'
require 'meilisearch/multi_search'
require 'meilisearch/tenant_token'
Expand Down
18 changes: 13 additions & 5 deletions lib/meilisearch/client.rb
Expand Up @@ -16,7 +16,8 @@ def raw_indexes(options = {})
def swap_indexes(*options)
mapped_array = options.map { |arr| { indexes: arr } }

http_post '/swap-indexes', mapped_array
response = http_post '/swap-indexes', mapped_array
Models::Task.new(response, task_endpoint)
end

def indexes(options = {})
Expand All @@ -35,14 +36,20 @@ def indexes(options = {})
def create_index(index_uid, options = {})
body = Utils.transform_attributes(options.merge(uid: index_uid))

http_post '/indexes', body
response = http_post '/indexes', body

Models::Task.new(response, task_endpoint)
end

# Synchronous version of create_index.
# Waits for the task to be achieved, be careful when using it.
def create_index!(index_uid, options = {})
task = create_index(index_uid, options)
wait_for_task(task['taskUid'])
Utils.soft_deprecate(
'Client#create_index!',
"client.create_index('#{index_uid}').await"
)

create_index(index_uid, options).await
end

def delete_index(index_uid)
Expand Down Expand Up @@ -118,7 +125,8 @@ def stats
### DUMPS

def create_dump
http_post '/dumps'
response = http_post '/dumps'
Models::Task.new(response, task_endpoint)
end

### SNAPSHOTS
Expand Down

0 comments on commit 65a34c9

Please sign in to comment.