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: sort_scope.rb
    path of file: ./repos/rails_stuff/lib/rails_stuff
    
    the code of the file until where you have to start completion: require 'has_scope'

module RailsStuff
  # Provides safe and flexible way to sort collections by user's input.
  # Uses `has_scope` gem.
  #
  # Supports different input format, and limits requested fields
  # to allowed subset.
  module SortScope
    # Register type for has_scop that accepts stings, hashes & arrays.
    HasScope::ALLOWED_TYPES[:any] = [[String, Hash, Array, Symbol, ActionController::Parameters]]

    # Setups has_scope to order collection by allowed columns.
    # Sort column is filtered by SortScope.filter_param 
    
    def has_sort_scope(config = {})
      @@_sort_scope_id ||= 0
      default = config[:default] || :id
      default = default.is_a?(Hash) ? default.stringify_keys : default.to_s
      allowed = Array.wrap(config[:by]).map(&:to_s)
      only_actions = config.fetch(:only, :index)
      order_method = config.fetch(:order_method, :order)
      # Counter added into scope name to allow to define multiple scopes in same controller.
      has_scope("sort_#{@@_sort_scope_id += 1}",
        as:           :sort,
        default:      nil,
        allow_blank:  true,
        only:         only_actions,
        type:         :any,
      ) do |c, scope, val|
        sort_args = SortScope.filter_param(val, c.params, allowed, default)
        c.instance_variable_set(:@current_sort_scope, sort_args)
        scope.public_send(order_method, sort_args)
      end
    end