Skip to content

Commit 4d7a593

Browse files
Merge #585
585: Rename top level module r=curquiza a=ellnix # Pull Request ## Related issue Fixes #523 Co-authored-by: ellnix <[email protected]>
2 parents 884f46d + 1ffa380 commit 4d7a593

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+238
-185
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ gem 'meilisearch'
7676
```ruby
7777
require 'meilisearch'
7878

79-
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
79+
client = Meilisearch::Client.new('http://127.0.0.1:7700', 'masterKey')
8080

8181
# An index is where the documents are stored.
8282
index = client.index('movies')

lib/meilisearch.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,40 @@
1212
require 'meilisearch/client'
1313
require 'meilisearch/index'
1414

15+
module Meilisearch
16+
end
17+
18+
# Softly deprecate the old spelling of the top level module
19+
# from MeiliSearch to Meilisearch
1520
module MeiliSearch
21+
class << self
22+
def const_missing(const_name)
23+
_warn_about_deprecation
24+
25+
Meilisearch.const_get(const_name)
26+
end
27+
28+
def method_missing(method_name, *args, **kwargs)
29+
_warn_about_deprecation
30+
31+
Meilisearch.send(method_name, *args, **kwargs)
32+
end
33+
34+
def respond_to_missing?(method_name, *)
35+
Meilisearch.respond_to?(method_name) || super
36+
end
37+
38+
private
39+
40+
def _warn_about_deprecation
41+
return if @warned
42+
43+
Meilisearch::Utils.logger.warn <<~RENAMED_MODULE_WARNING
44+
[meilisearch-ruby] The top-level module of Meilisearch has been renamed.
45+
[meilisearch-ruby] Please update "MeiliSearch" to "Meilisearch".
46+
RENAMED_MODULE_WARNING
47+
48+
@warned = true
49+
end
50+
end
1651
end

lib/meilisearch/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

3-
module MeiliSearch
3+
module Meilisearch
44
class Client < HTTPRequest
5-
include MeiliSearch::TenantToken
6-
include MeiliSearch::MultiSearch
5+
include Meilisearch::TenantToken
6+
include Meilisearch::MultiSearch
77

88
### INDEXES
99

lib/meilisearch/error.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# frozen_string_literal: true
22

3-
module MeiliSearch
3+
module Meilisearch
44
class Error < StandardError
55
end
66

77
class ApiError < Error
88
# :http_code # e.g. 400, 404...
99
# :http_message # e.g. Bad Request, Not Found...
10-
# :http_body # The response body received from the MeiliSearch API
11-
# :ms_code # The error code given by the MeiliSearch API
12-
# :ms_type # The error type given by the MeiliSearch API
13-
# :ms_link # The documentation link given by the MeiliSearch API
14-
# :ms_message # The error message given by the MeiliSearch API
10+
# :http_body # The response body received from the Meilisearch API
11+
# :ms_code # The error code given by the Meilisearch API
12+
# :ms_type # The error type given by the Meilisearch API
13+
# :ms_link # The documentation link given by the Meilisearch API
14+
# :ms_message # The error message given by the Meilisearch API
1515
# :message # The detailed error message of this error class
1616

1717
attr_reader :http_code, :http_message, :http_body, :ms_code, :ms_type, :ms_link, :ms_message, :message
@@ -26,7 +26,7 @@ def initialize(http_code, http_message, http_body)
2626
@http_body = parse_body(http_body)
2727
@ms_code = @http_body['code']
2828
@ms_type = @http_body['type']
29-
@ms_message = @http_body.fetch('message', 'MeiliSearch API has not returned any error message')
29+
@ms_message = @http_body.fetch('message', 'Meilisearch API has not returned any error message')
3030
@ms_link = @http_body.fetch('link', '<no documentation link found>')
3131
@message = "#{http_code} #{http_message} - #{@ms_message}. See #{ms_link}."
3232
super(details)
@@ -41,22 +41,22 @@ def parse_body(http_body)
4141
{}
4242
end
4343
rescue JSON::ParserError
44-
# We might receive a JSON::ParserError when, for example, MeiliSearch is running behind
44+
# We might receive a JSON::ParserError when, for example, Meilisearch is running behind
4545
# some proxy (ELB or Nginx, for example), and the request timeouts, returning us
4646
# a raw HTML body instead of a JSON as we were expecting
4747
{ 'message' => "The server has not returned a valid JSON HTTP body: #{http_body}" }
4848
end
4949

5050
def details
51-
"MeiliSearch::ApiError - code: #{@ms_code} - type: #{ms_type} - message: #{@ms_message} - link: #{ms_link}"
51+
"Meilisearch::ApiError - code: #{@ms_code} - type: #{ms_type} - message: #{@ms_message} - link: #{ms_link}"
5252
end
5353
end
5454

5555
class CommunicationError < Error
5656
attr_reader :message
5757

5858
def initialize(message)
59-
@message = "An error occurred while trying to connect to the MeiliSearch instance: #{message}"
59+
@message = "An error occurred while trying to connect to the Meilisearch instance: #{message}"
6060
super(@message)
6161
end
6262
end
@@ -80,8 +80,8 @@ def initialize(message = nil)
8080
end
8181

8282
module TenantToken
83-
class ExpireOrInvalidSignature < MeiliSearch::Error; end
84-
class InvalidApiKey < MeiliSearch::Error; end
85-
class InvalidSearchRules < MeiliSearch::Error; end
83+
class ExpireOrInvalidSignature < Meilisearch::Error; end
84+
class InvalidApiKey < Meilisearch::Error; end
85+
class InvalidSearchRules < Meilisearch::Error; end
8686
end
8787
end

lib/meilisearch/http_request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'httparty'
44
require 'meilisearch/error'
55

6-
module MeiliSearch
6+
module Meilisearch
77
class HTTPRequest
88
include HTTParty
99

@@ -93,7 +93,7 @@ def build_default_options_headers
9393
'Authorization' => ("Bearer #{@api_key}" unless @api_key.nil?),
9494
'User-Agent' => [
9595
@options.fetch(:client_agents, []),
96-
MeiliSearch.qualified_version
96+
Meilisearch.qualified_version
9797
].flatten.join(';')
9898
}.compact
9999
end

lib/meilisearch/index.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'meilisearch/http_request'
44

5-
module MeiliSearch
5+
module Meilisearch
66
class Index < HTTPRequest
77
attr_reader :uid, :primary_key, :created_at, :updated_at
88

@@ -233,7 +233,7 @@ def delete_documents!(documents_ids)
233233

234234
def delete_document(document_id)
235235
if document_id.nil? || document_id.to_s.empty?
236-
raise MeiliSearch::InvalidDocumentId, 'document_id cannot be empty or nil'
236+
raise Meilisearch::InvalidDocumentId, 'document_id cannot be empty or nil'
237237
end
238238

239239
encode_document = URI.encode_www_form_component(document_id)

lib/meilisearch/models/task.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'forwardable'
44

5-
module MeiliSearch
5+
module Meilisearch
66
module Models
77
class Task
88
extend Forwardable
@@ -88,7 +88,7 @@ def refresh(with: nil)
8888
self.metadata = with || @task_endpoint.task(uid)
8989

9090
self
91-
rescue MeiliSearch::ApiError => e
91+
rescue Meilisearch::ApiError => e
9292
raise e unless e.http_code == 404
9393

9494
@deleted = true

lib/meilisearch/multi_search.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module MeiliSearch
3+
module Meilisearch
44
module MultiSearch
55
def multi_search(data)
66
body = Utils.transform_attributes(data)

lib/meilisearch/task.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'meilisearch/http_request'
44
require 'timeout'
55

6-
module MeiliSearch
6+
module Meilisearch
77
class Task < HTTPRequest
88
ALLOWED_PARAMS = [
99
:limit, :from, :index_uids, :types, :statuses, :uids, :canceled_by,
@@ -46,7 +46,7 @@ def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
4646
end
4747
end
4848
rescue Timeout::Error
49-
raise MeiliSearch::TimeoutError
49+
raise Meilisearch::TimeoutError
5050
end
5151

5252
private

lib/meilisearch/tenant_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module MeiliSearch
3+
module Meilisearch
44
module TenantToken
55
HEADER = {
66
typ: 'JWT',

0 commit comments

Comments
 (0)