Class: Esse::AsyncIndexing::Actions::UpdateDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/async_indexing/actions/update_document.rb

Constant Summary collapse

DOC_ARGS =
%i[lazy_attributes]

Class Method Summary collapse

Class Method Details

.call(index_class_name, repo_name, document_id, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/esse/async_indexing/actions/update_document.rb', line 7

def self.call(index_class_name, repo_name, document_id, options = {})
  index_class, repo_class = CoerceIndexRepository.call(index_class_name, repo_name)
  bulk_opts = Esse::HashUtils.deep_transform_keys(options, &:to_sym)
  bulk_opts.delete_if { |k, _| DOC_ARGS.include?(k) }
  find_opts = options.slice(*DOC_ARGS)

  doc = repo_class.documents(**find_opts, id: document_id).first
  return :not_found unless doc

  index_class.update(doc, **bulk_opts)
  :indexed
end