meilisearch-rails 0.4.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -6
- data/LICENSE +1 -1
- data/README.md +73 -61
- data/Rakefile +1 -1
- data/lib/meilisearch/rails/configuration.rb +23 -0
- data/lib/meilisearch/rails/errors.rb +14 -0
- data/lib/meilisearch/rails/ms_job.rb +11 -0
- data/lib/meilisearch/rails/pagination/kaminari.rb +48 -0
- data/lib/meilisearch/rails/pagination/will_paginate.rb +22 -0
- data/lib/meilisearch/rails/pagination.rb +20 -0
- data/lib/meilisearch/rails/railtie.rb +14 -0
- data/lib/meilisearch/rails/tasks/meilisearch.rake +22 -0
- data/lib/meilisearch/rails/utilities.rb +46 -0
- data/lib/meilisearch/{version.rb → rails/version.rb} +3 -1
- data/lib/meilisearch-rails.rb +693 -695
- data/meilisearch-rails.gemspec +12 -10
- metadata +19 -33
- data/lib/meilisearch/configuration.rb +0 -21
- data/lib/meilisearch/errors.rb +0 -12
- data/lib/meilisearch/ms_job.rb +0 -9
- data/lib/meilisearch/pagination/kaminari.rb +0 -46
- data/lib/meilisearch/pagination/will_paginate.rb +0 -20
- data/lib/meilisearch/pagination.rb +0 -18
- data/lib/meilisearch/railtie.rb +0 -12
- data/lib/meilisearch/tasks/meilisearch.rake +0 -17
- data/lib/meilisearch/utilities.rb +0 -44
@@ -0,0 +1,46 @@
|
|
1
|
+
module MeiliSearch
|
2
|
+
module Rails
|
3
|
+
module Utilities
|
4
|
+
class << self
|
5
|
+
def get_model_classes
|
6
|
+
if ::Rails.application && defined?(::Rails.autoloaders) && ::Rails.autoloaders.zeitwerk_enabled?
|
7
|
+
Zeitwerk::Loader.eager_load_all
|
8
|
+
elsif ::Rails.application
|
9
|
+
::Rails.application.eager_load!
|
10
|
+
end
|
11
|
+
klasses = MeiliSearch::Rails.instance_variable_get(:@included_in)
|
12
|
+
(klasses + klasses.map(&:descendants).flatten).uniq
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear_all_indexes
|
16
|
+
get_model_classes.each(&:clear_index!)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reindex_all_models
|
20
|
+
klasses = get_model_classes
|
21
|
+
|
22
|
+
::Rails.logger.info "\n\nReindexing #{klasses.count} models: #{klasses.to_sentence}.\n"
|
23
|
+
|
24
|
+
klasses.each do |klass|
|
25
|
+
::Rails.logger.info klass
|
26
|
+
::Rails.logger.info "Reindexing #{klass.count} records..."
|
27
|
+
|
28
|
+
klass.ms_reindex!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_settings_all_models
|
33
|
+
klasses = get_model_classes
|
34
|
+
|
35
|
+
::Rails.logger.info "\n\nPushing settings for #{klasses.count} models: #{klasses.to_sentence}.\n"
|
36
|
+
|
37
|
+
klasses.each do |klass|
|
38
|
+
::Rails.logger.info "Pushing #{klass} settings..."
|
39
|
+
|
40
|
+
klass.ms_set_settings
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|