You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: diff_collection.rb
    path of file: ./repos/gitlabhq/lib/gitlab/git
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

# Gitaly note: JV: no RPC's here.

module Gitlab
  module Git
    class DiffCollection
      include Enumerable


    
      def each_serialized_patch
        i = @array.length

        @iterator.each_with_index do |raw, iterator_index|
          @empty = false

          if @enforce_limits && i >= limits[:max_files]
            @overflow = true
            @overflow_max_files = true
            break
          end

          # Discard generated field if it is already set when FF is disabled
          raw_data = @collapse_generated ? raw : raw.except(:generated)

          diff = Gitlab::Git::Diff.new(raw_data, expanded: expand_diff?)

          if !expand_diff? && over_safe_limits?(i) && diff.line_count > 0
            diff.collapse!
          end