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: unit_of_work.rb
    path of file: ./repos/workarea/core/app/models/workarea/inventory
    
    the code of the file until where you have to start completion: module Workarea
  module Inventory
    # This class handles the transaction details of doing an inventory
    # purchase or rollback.
    #
    class UnitOfWork
      class Failure < StandardError; end

      at
    
      def restock(quantities = {})
        quantities.each do |sku, quantity|
          item = items.detect { |i| i.sku == sku }

          if item.expired_backorder?
            available_to_restock = quantity
            backordered_to_restock = 0
          else
            available_to_restock = [item.available, quantity].min
            backordered_to_restock = quantity - available_to_restock
          end

          record = records.for_sku(sku)
          record.release(available_to_restock, backordered_to_restock)

          available_restocked = [available_to_restock, item.available].min

          item.available -= available_restocked
          item.backordered -= if item.expired_backorder?
                                available_to_restock - available_restocked
                              else
                                backordered_to_restock
                              end