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: permalinks.rb
    path of file: ./repos/solidus/core/lib/spree/core
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Spree
  module Core
    module Permalinks
      extend ActiveSupport::Concern

      included do
        class_attribute :permalink_
    
      def save_permalink(permalink_value = to_param)
        permalink_value ||= generate_permalink
        permalink_field = self.class.permalink_field

        loop do
          other = self.class.where(permalink_field => permalink_value)
          break unless other.exists?

          # Try again with a new value
          permalink_value = generate_permalink
        end
        write_attribute(permalink_field, permalink_value)
      end