<commit_before>module Godmin
  module Resource
    module Pagination
      extend ActiveSupport::Concern

      included do
        helper_method :current_page
        helper_method :pages
        helper_method :total_pages
        helper_method :total_resources
      end

      def apply_pagination(resources)
        resources.limit(pagination_limit).offset(pagination_offset)
      end

      private

      def current_page
        params[:page].present? ? params[:page].to_i : 1
      end

      def pagination_limit
        self.class.per_page
      end

      def pagination_offset
        (params[:page].to_i * self.class.per_page) - self.class.per_page
      end

      def pages
        pages = (1..total_pages).to_a

        return pages unless total_pages > 7

        if current_page < 7
          pages.slice(0, 7)
        elsif current_page > (total_pages - 7)
          pages.slice(-7, 7)
        else
          pages.slice(pages.index(current_page) - (7 / 2), 7)
        end
      end

      def total_pages<commit_msg>Replaces magic number with constant<commit_after>module Godmin
  module Resource
    module Pagination
      extend ActiveSupport::Concern

      WINDOW_SIZE = 7

      included do
        helper_method :current_page
        helper_method :pages
        helper_method :total_pages
        helper_method :total_resources
      end

      def apply_pagination(resources)
        resources.limit(pagination_limit).offset(pagination_offset)
      end

      private

      def current_page
        params[:page].present? ? params[:page].to_i : 1
      end

      def pagination_limit
        self.class.per_page
      end

      def pagination_offset
        (params[:page].to_i * self.class.per_page) - self.class.per_page
      end

      def pages
        pages = (1..total_pages).to_a

        return pages unless total_pages > WINDOW_SIZE

        if current_page < WINDOW_SIZE
          pages.slice(0, WINDOW_SIZE)
        elsif current_page > (total_pages - WINDOW_SIZE)
          pages.slice(-WINDOW_SIZE, WINDOW_SIZE)
        else
          pages.slice(pages.index(current_page) - (WINDOW_SIZE / 2), WINDOW_SIZE)
        end
      end

      def total_pages
{'fraction_non_alphanumeric': 0.06775807185084129, 'fraction_numerical': 0.007730786721236926, 'mean_word_length': 2.076923076923077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5916533', 'n_tokens_mistral': 670, 'n_tokens_neox': 631, 'n_words': 143}