Skip to content

Commit c39c607

Browse files
authored
Merge pull request #36 from meilisearch/refacto
Simplify files organization
2 parents 5c05e0e + d14971c commit c39c607

29 files changed

+442
-604
lines changed

.rubocop_todo.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2020-03-11 15:59:15 +0100 using RuboCop version 0.79.0.
3+
# on 2020-05-24 23:52:41 +0200 using RuboCop version 0.84.0.
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: 21
9+
# Offense count: 19
1010
# Configuration parameters: CountComments, ExcludedMethods.
1111
# ExcludedMethods: refine
1212
Metrics/BlockLength:
13-
Max: 343
13+
Max: 434
14+
15+
# Offense count: 1
16+
# Configuration parameters: CountComments.
17+
Metrics/ClassLength:
18+
Max: 160
1419

1520
# Offense count: 1
1621
# Configuration parameters: CountComments, ExcludedMethods.
@@ -20,15 +25,8 @@ Metrics/MethodLength:
2025
# Offense count: 1
2126
Naming/AccessorMethodName:
2227
Exclude:
23-
- 'lib/meilisearch/index/updates.rb'
28+
- 'lib/meilisearch/index.rb'
2429

25-
# Offense count: 17
30+
# Offense count: 5
2631
Style/Documentation:
2732
Enabled: false
28-
29-
# Offense count: 73
30-
# Cop supports --auto-correct.
31-
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
32-
# URISchemes: http, https
33-
Layout/LineLength:
34-
Max: 107

lib/meilisearch/client.rb

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,94 @@
11
# frozen_string_literal: true
22

33
require 'meilisearch/http_request'
4-
require 'meilisearch/client/keys'
5-
require 'meilisearch/client/stats'
6-
require 'meilisearch/client/health'
7-
require 'meilisearch/client/indexes'
84

95
module MeiliSearch
106
class Client < HTTPRequest
11-
include MeiliSearch::Client::Keys
12-
include MeiliSearch::Client::Stats
13-
include MeiliSearch::Client::Health
14-
include MeiliSearch::Client::Indexes
7+
### INDEXES
8+
9+
def indexes
10+
http_get '/indexes'
11+
end
12+
13+
def show_index(index_uid)
14+
index_object(index_uid).show
15+
end
16+
17+
# Usage:
18+
# create_index('indexUID')
19+
# create_index(uid: 'indexUID')
20+
# create_index(uid: 'indexUID', primaryKey: 'id')
21+
def create_index(attributes)
22+
body = if attributes.is_a?(Hash)
23+
attributes
24+
else
25+
{ uid: attributes }
26+
end
27+
res = http_post '/indexes', body
28+
index_object(res['uid'])
29+
end
30+
31+
def delete_index(index_uid)
32+
index_object(index_uid).delete
33+
end
34+
35+
# Usage:
36+
# index('indexUID')
37+
# index(uid: 'indexUID')
38+
def index(attribute)
39+
uid = attribute.is_a?(Hash) ? attribute[:uid] : attribute
40+
raise IndexUidError if uid.nil?
41+
42+
index_object(uid)
43+
end
44+
alias get_index index
45+
46+
### KEYS
47+
48+
def keys
49+
http_get '/keys'
50+
end
51+
alias get_keys keys
52+
53+
### HEALTH
54+
55+
def healthy?
56+
http_get '/health'
57+
true
58+
rescue StandardError
59+
false
60+
end
61+
62+
def health
63+
http_get '/health'
64+
end
65+
66+
def update_health(bool)
67+
http_put '/health', health: bool
68+
end
69+
70+
### STATS
71+
72+
def version
73+
http_get '/version'
74+
end
75+
76+
def sysinfo
77+
http_get '/sys-info'
78+
end
79+
80+
def pretty_sysinfo
81+
http_get '/sys-info/pretty'
82+
end
83+
84+
def stats
85+
http_get '/stats'
86+
end
87+
88+
private
89+
90+
def index_object(uid)
91+
Index.new(uid, @base_url, @api_key)
92+
end
1593
end
1694
end

lib/meilisearch/client/health.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/meilisearch/client/indexes.rb

Lines changed: 0 additions & 50 deletions
This file was deleted.

lib/meilisearch/client/keys.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/meilisearch/client/stats.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/meilisearch/http_request.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ def http_put(path = '', body = nil, params = nil)
5353
validate(response)
5454
end
5555

56-
def http_patch(path = '', body = nil)
57-
body = body.to_json unless body.nil?
58-
response = self.class.patch(
59-
@base_url + path,
60-
body: body,
61-
headers: @headers,
62-
timeout: 1
63-
)
64-
validate(response)
65-
end
66-
6756
def http_delete(path = '')
6857
response = self.class.delete(
6958
@base_url + path,

0 commit comments

Comments
 (0)