def apply_ordering_to_scope(scope, user_params)
      sort_name, direction = calculate_sort_name_and_direction(user_params)
      order = configuration[:sort_orders].fetch(sort_name, {})[:value]

      ordered_scope = case order
        when Proc
          fresh_helper_instance.instance_exec(scope, direction, &order)
        when nil
          scope
        else
          scope.reorder(order.to_s + " " + direction)
      end

      fallback_deterministic_sort = assemble_primary_key_sort(scope)
      # Chain on a tiebreaker sort to ensure deterministic ordering of multiple pages of data

      if fallback_deterministic_sort
        ordered_scope.order(fallback_deterministic_sort)
      else
        ordered_scope
      end
    end
def apply_ordering_to_scope(scope, user_params)
      sort_name, direction = calculate_sort_name_and_direction(user_params)
      order = configuration[:sort_orders].fetch(sort_name, {})[:value]

      ordered_scope = case order
        when Proc
          fresh_helper_instance.instance_exec(scope, direction, &order)
        when nil
          scope
        else
          scope.reorder(order.to_s + " " + direction)
      end

      fallback_deterministic_sort = assemble_primary_key_sort(scope)
      # Chain on a tiebreaker sort to ensure deterministic ordering of multiple pages of data

      if fallback_deterministic_sort
        ordered_scope.order(fallback_deterministic_sort)
      else
        ordered_scope
      end
    end
Given user params, apply a validated sort order to the given scope.