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: persist_derivatives.rb
    path of file: ./repos/hyrax/app/services/hyrax
    
    the code of the file until where you have to start completion: # frozen_string_literal: true
module Hyrax
  class PersistDerivatives < Hydra::Derivatives::PersistOutputFileService
    # Persists a derivative to the local file system.
    # This Service conforms to the signature of `Hydra::Derivatives::PersistOutputFileService`.
    # 
    
    def self.output_file(directives, &blk)
      raise ArgumentError, "No :url was provided in the transcoding directives" unless directives.key?(:url)
      uri = URI(directives.fetch(:url))
      raise ArgumentError, "Must provide a file uri" unless uri.scheme == 'file'
      output_file_dir = File.dirname(uri.path)
      FileUtils.mkdir_p(output_file_dir) unless File.directory?(output_file_dir)
      File.open(uri.path, 'wb', &blk)
    end