Skip to content

Commit a25439f

Browse files
committed
Add deprecation message for top-level module
1 parent a7fcee6 commit a25439f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

lib/meilisearch.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,45 @@
1414

1515
module Meilisearch
1616
end
17+
18+
module MeiliSearch
19+
# Softly deprecate the old spelling of the top level module
20+
# from MeiliSearch to Meilisearch
21+
def self.const_missing(const_name)
22+
return super if @warned
23+
24+
Meilisearch::Utils.logger.warn <<~RENAMED_MODULE_WARNING
25+
[meilisearch-ruby] The top-level module of Meilisearch has been renamed.
26+
[meilisearch-ruby] Please update "MeiliSearch" to "Meilisearch".
27+
RENAMED_MODULE_WARNING
28+
29+
Meilisearch.constants.each do |constant|
30+
const_set(constant, Meilisearch.const_get(constant))
31+
end
32+
33+
@warned = true
34+
35+
# Now that all the proper constants have been set,
36+
# we can tell ruby to search for the const in MeiliSearch again.
37+
# If it's still not found, then it does not exist in
38+
# Meilisearch and the call to `super` will throw a normal error
39+
const_get(const_name)
40+
end
41+
42+
def self.method_missing(method_name)
43+
unless @warned
44+
Meilisearch::Utils.logger.warn <<~RENAMED_MODULE_WARNING
45+
[meilisearch-ruby] The top-level module of Meilisearch has been renamed.
46+
[meilisearch-ruby] Please update "MeiliSearch" to "Meilisearch".
47+
RENAMED_MODULE_WARNING
48+
49+
Meilisearch.constants.each do |constant|
50+
const_set(constant, Meilisearch.const_get(constant))
51+
end
52+
end
53+
54+
@warned = true
55+
56+
Meilisearch.send(method_name)
57+
end
58+
end

0 commit comments

Comments
 (0)