lib/searchkick.rb in searchkick-3.1.2 vs lib/searchkick.rb in searchkick-3.1.3

- old
+ new

@@ -1,6 +1,6 @@ -require "active_model" +require "active_support" require "active_support/core_ext/hash/deep_merge" require "elasticsearch" require "hashie" require "searchkick/bulk_indexer" @@ -15,33 +15,20 @@ require "searchkick/record_data" require "searchkick/record_indexer" require "searchkick/results" require "searchkick/version" +require "searchkick/railtie" if defined?(Rails) require "searchkick/logging" if defined?(ActiveSupport::Notifications) -begin - require "rake" -rescue LoadError - # do nothing -end -require "searchkick/tasks" if defined?(Rake) - -# background jobs -begin - require "active_job" -rescue LoadError - # do nothing -end -if defined?(ActiveJob) - require "searchkick/bulk_reindex_job" - require "searchkick/process_batch_job" - require "searchkick/process_queue_job" - require "searchkick/reindex_v2_job" -end - module Searchkick + # background jobs + autoload :BulkReindexJob, "searchkick/bulk_reindex_job" + autoload :ProcessBatchJob, "searchkick/process_batch_job" + autoload :ProcessQueueJob, "searchkick/process_queue_job" + autoload :ReindexV2Job, "searchkick/reindex_v2_job" + class Error < StandardError; end class MissingIndexError < Error; end class UnsupportedVersionError < Error; end class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end class DangerousOperation < Error; end @@ -102,12 +89,12 @@ klass = index_name.first options.delete(:index_name) end end + options = options.merge(block: block) if block query = Searchkick::Query.new(klass, term, options) - block.call(query.body) if block if options[:execute] == false query else query.execute end @@ -239,9 +226,10 @@ end end end # TODO find better ActiveModel hook +require "active_model/callbacks" ActiveModel::Callbacks.include(Searchkick::Model) ActiveSupport.on_load(:active_record) do extend Searchkick::Model end