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.
@@ -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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.4.1'
4
+ module Rails
5
+ VERSION = '0.5.2'
6
+ end
5
7
  end