Skip to content

Commit

Permalink
chore: rename attributes kwarg to lazy_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Jul 12, 2024
1 parent c6a4c33 commit b30a35c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/esse/index/documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def import(*repo_types, context: {}, eager_include_document_attributes: false, l
doc_attrs[:lazy] -= doc_attrs[:eager]

context ||= {}
context[:attributes] = doc_attrs[:eager] if doc_attrs[:eager].any?
context[:lazy_attributes] = doc_attrs[:eager] if doc_attrs[:eager].any?
repo.each_serialized_batch(**context) do |batch|
# Elasticsearch 6.x and older have multiple types per index.
# This gem supports multiple types per index for backward compatibility, but we recommend to update
Expand Down
8 changes: 4 additions & 4 deletions lib/esse/repository/object_document_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ def collection(collection_klass = nil, **_, &block)
# @param [Hash] kwargs The context
# @return [Enumerator] The enumerator
# @yield [Array, **context] serialized collection and the optional context from the collection
def each_serialized_batch(attributes: false, **kwargs)
def each_serialized_batch(lazy_attributes: false, **kwargs)
each_batch(**kwargs) do |*args|
batch, collection_context = args
collection_context ||= {}
entries = [*batch].map { |entry| serialize(entry, **collection_context) }.compact
if attributes
attributes = lazy_document_attribute_names(attributes) unless attributes.is_a?(Array)
attributes.each do |attr_name|
if lazy_attributes
attrs = lazy_attributes.is_a?(Array) ? lazy_attributes : lazy_document_attribute_names(lazy_attributes)
attrs.each do |attr_name|
retrieve_lazy_attribute_values(attr_name, entries).each do |doc_header, value|
doc = entries.find { |d| doc_header.id.to_s == d.id.to_s && doc_header.type == d.type && doc_header.routing == d.routing }
doc&.mutate(attr_name) { value }
Expand Down
10 changes: 5 additions & 5 deletions spec/esse/repository/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,20 @@
context 'with lazy_load_attributes' do
include_context 'with stories index definition'

it 'yields serialized objects with lazy attributes when passing attributes: true' do
it 'yields serialized objects with lazy attributes when passing lazy_attributes: true' do
expected_data = []
expect {
StoriesIndex::Story.each_serialized_batch(attributes: true) do |batch|
StoriesIndex::Story.each_serialized_batch(lazy_attributes: true) do |batch|
expected_data.push(*batch)
end
}.not_to raise_error
expect(expected_data.select { |doc| doc.to_h.key?(:tags) && doc.to_h.key?(:tags_count) }).not_to be_empty
end

it 'yields serialized objects without lazy attributes when passing attributes: false' do
it 'yields serialized objects without lazy attributes when passing lazy_attributes: false' do
expected_data = []
expect {
StoriesIndex::Story.each_serialized_batch(attributes: false) do |batch|
StoriesIndex::Story.each_serialized_batch(lazy_attributes: false) do |batch|
expected_data.push(*batch)
end
}.not_to raise_error
Expand All @@ -180,7 +180,7 @@
it 'yields serialized objects with lazy attributes when passing specific attributes' do
expected_data = []
expect {
StoriesIndex::Story.each_serialized_batch(attributes: %i[tags]) do |batch|
StoriesIndex::Story.each_serialized_batch(lazy_attributes: %i[tags]) do |batch|
expected_data.push(*batch)
end
}.not_to raise_error
Expand Down

0 comments on commit b30a35c

Please sign in to comment.