Commit 9f2e8dd35140def5af54bae4f54f134d26350b1e

Authored by Andrew Kane
1 parent f13fb329

DRY warn code [skip ci]

lib/searchkick.rb
... ... @@ -192,6 +192,10 @@ module Searchkick
192 192 end
193 193 end
194 194  
  195 + def self.warn(message)
  196 + warn "[searchkick] WARNING: #{message}"
  197 + end
  198 +
195 199 # private
196 200 def self.load_records(records, ids)
197 201 records =
... ...
lib/searchkick/query.rb
... ... @@ -432,7 +432,7 @@ module Searchkick
432 432  
433 433 models = Array(options[:models])
434 434 if models.any? { |m| m != m.searchkick_klass }
435   - warn "[searchkick] WARNING: Passing child models to models option throws off hits and pagination - use type option instead"
  435 + Searchkick.warn("Passing child models to models option throws off hits and pagination - use type option instead")
436 436  
437 437 # uncomment once aliases are supported with _index
438 438 # see https://github.com/elastic/elasticsearch/issues/23306
... ... @@ -986,13 +986,13 @@ module Searchkick
986 986 {bool: {must_not: {exists: {field: field}}}}
987 987 elsif value.is_a?(Regexp)
988 988 if value.casefold?
989   - warn "[searchkick] Case-insensitive flag does not work with Elasticsearch"
  989 + Searchkick.warn("Case-insensitive flag does not work with Elasticsearch")
990 990 end
991 991  
992 992 source = value.source
993 993 unless source.start_with?("\\A") && source.end_with?("\\z")
994 994 # https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html
995   - warn "[searchkick] Regular expressions are always anchored in Elasticsearch"
  995 + Searchkick.warn("Regular expressions are always anchored in Elasticsearch")
996 996 end
997 997  
998 998 # TODO handle other anchor characters, like ^, $, \Z
... ...
lib/searchkick/results.rb
... ... @@ -62,7 +62,7 @@ module Searchkick
62 62 end
63 63  
64 64 if missing_ids.any?
65   - warn "[searchkick] WARNING: Records in search index do not exist in database: #{missing_ids.join(", ")}"
  65 + Searchkick.warn("Records in search index do not exist in database: #{missing_ids.join(", ")}")
66 66 end
67 67  
68 68 results
... ...