Class: Esse::AsyncIndexing::ActiveRecordCallbacks::LazyUpdateAttribute

Inherits:
Callback
  • Object
show all
Defined in:
lib/esse/async_indexing/active_record_callbacks/lazy_update_attribute.rb

Constant Summary collapse

LAZY_ATTR_WORKER =
"Esse::AsyncIndexing::Jobs::UpdateLazyDocumentAttributeJob"

Instance Attribute Summary collapse

Attributes inherited from Callback

#service_name

Instance Method Summary collapse

Constructor Details

#initialize(service_name:, attribute_name:, with: nil, **kwargs) ⇒ LazyUpdateAttribute

Returns a new instance of LazyUpdateAttribute.



10
11
12
13
# File 'lib/esse/async_indexing/active_record_callbacks/lazy_update_attribute.rb', line 10

def initialize(service_name:, attribute_name:, with: nil, **kwargs)
  @attribute_name = attribute_name
  super(service_name: service_name, **kwargs)
end

Instance Attribute Details

#attribute_nameObject (readonly)

Returns the value of attribute attribute_name.



8
9
10
# File 'lib/esse/async_indexing/active_record_callbacks/lazy_update_attribute.rb', line 8

def attribute_name
  @attribute_name
end

Instance Method Details

#call(model) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/esse/async_indexing/active_record_callbacks/lazy_update_attribute.rb', line 15

def call(model)
  if (doc_ids = resolve_document_ids(model))
    Esse::AsyncIndexing.worker(LAZY_ATTR_WORKER, service: service_name)
      .with_args(repo.index.name, repo.repo_name, attribute_name.to_s, doc_ids, Esse::HashUtils.deep_transform_keys(options, &:to_s))
      .push
  end

  true
end