Skip to content

Commit

Permalink
feat: do not create new array when values are already a doc instances
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Aug 20, 2024
1 parent 27b8491 commit 1c0df51
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/esse/lazy_document_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ class LazyDocumentHeader
ACCEPTABLE_DOC_TYPES = [nil, '_doc', 'doc'].freeze

def self.coerce_each(values)
values = Esse::ArrayUtils.wrap(values)
return values if values.all? do |value|
ACCEPTABLE_CLASSES.any? { |klass| value.is_a?(klass) }
end

arr = []
Esse::ArrayUtils.wrap(values).flatten.map do |value|
values.flatten.map do |value|
instance = coerce(value)
arr << instance if instance && !instance.id.nil?
end
Expand Down

0 comments on commit 1c0df51

Please sign in to comment.