class Google::Cloud::Storage::Service

def compose_file_source_objects source_files, if_source_generation_match

def compose_file_source_objects source_files, if_source_generation_match
  source_objects = source_files.map do |file|
    if file.is_a? Google::Cloud::Storage::File
      Google::Apis::StorageV1::ComposeRequest::SourceObject.new \
        name: file.name,
        generation: file.generation
    else
      Google::Apis::StorageV1::ComposeRequest::SourceObject.new \
        name: file
    end
  end
  return source_objects unless if_source_generation_match
  if source_files.count != if_source_generation_match.count
    raise ArgumentError, "if provided, if_source_generation_match length must match sources length"
  end
  if_source_generation_match.each_with_index do |generation, i|
    next unless generation
    object_preconditions = Google::Apis::StorageV1::ComposeRequest::SourceObject::ObjectPreconditions.new(
      if_generation_match: generation
    )
    source_objects[i].object_preconditions = object_preconditions
  end
  source_objects
end