Class: Gitlab::GitalyClient::BlobsStitcher

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gitlab/gitaly_client/blobs_stitcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(rpc_response) ⇒ BlobsStitcher

Returns a new instance of BlobsStitcher.


8
9
10
# File 'lib/gitlab/gitaly_client/blobs_stitcher.rb', line 8

def initialize(rpc_response)
  @rpc_response = rpc_response
end

Instance Method Details

#each {|new_blob(current_blob_data)| ... } ⇒ Object

Yields:

  • (new_blob(current_blob_data))

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/gitaly_client/blobs_stitcher.rb', line 12

def each
  current_blob_data = nil

  @rpc_response.each do |msg|
    if msg.oid.blank? && msg.data.blank?
      next
    elsif msg.oid.present?
      yield new_blob(current_blob_data) if current_blob_data

      current_blob_data = msg.to_h.slice(:oid, :path, :size, :revision, :mode)
      current_blob_data[:data] = msg.data.dup
    else
      current_blob_data[:data] << msg.data
    end
  end

  yield new_blob(current_blob_data) if current_blob_data
end