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: errors.rb
    path of file: ./repos/stitches/lib/stitches
    
    the code of the file until where you have to start completion: module Stitches
  # A container for error messages you intend to send as a response to an API request.
  # The canonical error format is a list of all errors that occured, with each error consistent of a code
  # (useful for programmatic logi
    
    def self.from_active_record_object(object)
      errors = object.errors.to_hash.map { |field,errors|
        code = "#{field}_invalid".parameterize
        message = if object.respond_to?(field) && object.send(field).respond_to?(:errors)
                    object.send(field).errors.full_messages.sort.join(', ')
                  else
                    object.errors.full_messages_for(field).sort.join(', ')
                  end