docbrown/app/services/data_sync/elasticsearch/base.rb
rhymes 6cd64c4071
Rubocop: enable and fix Style/Send and Style/Next (#9366)
* Enable and fix Style/Send

* Enable and fix Style/Next

* Fix private cookies send

* Fix merging indentation issues
2020-07-20 16:28:00 +02:00

33 lines
655 B
Ruby

module DataSync
module Elasticsearch
class Base
attr_reader :updated_record
def initialize(updated_record)
@updated_record = updated_record
end
def call
return unless sync_needed?
sync_related_documents
end
private
def sync_needed?
updated_fields.slice(*self.class::SHARED_FIELDS).any?
end
def sync_related_documents
self.class::RELATED_DOCS.each do |relation_name|
__send__(relation_name).find_each(&:index_to_elasticsearch)
end
end
def updated_fields
updated_record.saved_changes
end
end
end
end