Skip to content

Commit 65a34c9

Browse files
Merge #498
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 <[email protected]>
2 parents dcc99be + 75017dc commit 65a34c9

29 files changed

+1832
-1239
lines changed

.rubocop_todo.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-01-16 21:52:52 UTC using RuboCop version 1.50.2.
3+
# on 2024-02-16 18:01:53 UTC using RuboCop version 1.50.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 55
9+
# Offense count: 63
1010
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1111
# AllowedMethods: refine
1212
Metrics/BlockLength:
13-
Max: 694
13+
Max: 581
1414

15-
# Offense count: 2
15+
# Offense count: 4
1616
# Configuration parameters: CountComments, CountAsOne.
1717
Metrics/ClassLength:
18-
Max: 373
18+
Max: 421
1919

2020
# Offense count: 1
2121
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'meilisearch/version'
44
require 'meilisearch/utils'
5+
require 'meilisearch/models/task'
56
require 'meilisearch/http_request'
67
require 'meilisearch/multi_search'
78
require 'meilisearch/tenant_token'

lib/meilisearch/client.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def raw_indexes(options = {})
1616
def swap_indexes(*options)
1717
mapped_array = options.map { |arr| { indexes: arr } }
1818

19-
http_post '/swap-indexes', mapped_array
19+
response = http_post '/swap-indexes', mapped_array
20+
Models::Task.new(response, task_endpoint)
2021
end
2122

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

38-
http_post '/indexes', body
39+
response = http_post '/indexes', body
40+
41+
Models::Task.new(response, task_endpoint)
3942
end
4043

4144
# Synchronous version of create_index.
4245
# Waits for the task to be achieved, be careful when using it.
4346
def create_index!(index_uid, options = {})
44-
task = create_index(index_uid, options)
45-
wait_for_task(task['taskUid'])
47+
Utils.soft_deprecate(
48+
'Client#create_index!',
49+
"client.create_index('#{index_uid}').await"
50+
)
51+
52+
create_index(index_uid, options).await
4653
end
4754

4855
def delete_index(index_uid)
@@ -118,7 +125,8 @@ def stats
118125
### DUMPS
119126

120127
def create_dump
121-
http_post '/dumps'
128+
response = http_post '/dumps'
129+
Models::Task.new(response, task_endpoint)
122130
end
123131

124132
### SNAPSHOTS

0 commit comments

Comments
 (0)