Skip to content

Commit 8f5c594

Browse files
committed
Extract a repeated code into a private method to reduce duplication
- Thus I'm not making fetch_info calls fetch_raw_info or vice-versa. Reasons: the benefit is small, we may mix concerns and hinder future reuses.
1 parent 7ed1f7a commit 8f5c594

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/meilisearch/index.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,29 @@ def initialize(index_uid, url, api_key = nil, primary_key = nil, options = {})
1515

1616
def fetch_info
1717
index_hash = http_get "/indexes/#{@uid}"
18-
@primary_key = index_hash['primaryKey']
19-
@created_at = Time.parse(index_hash['createdAt'])
20-
@updated_at = Time.parse(index_hash['updatedAt'])
18+
set_base_properties index_hash
2119
self
2220
end
2321

2422
def fetch_raw_info
2523
index_hash = http_get "/indexes/#{@uid}"
26-
@primary_key = index_hash['primaryKey']
27-
@created_at = Time.parse(index_hash['createdAt'])
28-
@updated_at = Time.parse(index_hash['updatedAt'])
24+
set_base_properties index_hash
2925
index_hash
3026
end
3127

3228
def update(body)
3329
index_hash = http_put "/indexes/#{@uid}", body
30+
set_base_properties index_hash
31+
self
32+
end
33+
alias update_index update
34+
35+
def set_base_properties(index_hash)
3436
@primary_key = index_hash['primaryKey']
3537
@created_at = Time.parse(index_hash['createdAt'])
3638
@updated_at = Time.parse(index_hash['updatedAt'])
37-
self
3839
end
39-
alias update_index update
40+
private :set_base_properties
4041

4142
def delete
4243
http_delete "/indexes/#{@uid}"

0 commit comments

Comments
 (0)