<commit_before>module RestPack
  module Serializable
    module Paging
      def page(options = {})
        apply_default_options! options

        page = options[:scope].paginate(
          page: options[:page],
          per_page: options[:page_size]
        )

        result = {}
        result[self.key] = page.map { |model| self.new.as_json(model) }

        result[self.meta_key] = {
          page: options[:page],
          page_size: options[:page_size],
          count: page.total_entries,
          page_count: (page.total_entries / options[:page_size]) + 1
        }

        result
      end

      private

      def apply_default_options!(options)
        options.reverse_merge!(
          page: 1,
          page_size: 10,
          includes: [],
          filters: {},
          sort_by: nil,
          sort_direction: :ascending
        )
        options[:scope] ||= default_scope<commit_msg>simplified Serializable.page method<commit_after>module RestPack
  module Serializable
    module Paging
      def page(options = {})
        apply_default_options! options

        page = options[:scope].paginate(
          page: options[:page],
          per_page: options[:page_size]
        )

        {
          self.key => serialize_page(page),
          self.meta_key => serialize_meta(page, options)
        }
      end

      private

      def serialize_page(page)
        page.map { |model| self.new.as_json(model) }
      end

      def serialize_meta(page, options)
        {
          page: options[:page],
          page_size: options[:page_size],
          count: page.total_entries,
          page_count: (page.total_entries / options[:page_size]) + 1
        }
      end

      def apply_default_options!(options)
        options.reverse_merge!(
          page: 1,
          page_size: 10,
          includes: [],
          filters: {},
          sort_by: nil,
          sort_direction: :ascending
        )
        options[:scope] ||= default_scope
{'fraction_non_alphanumeric': 0.10353535353535354, 'fraction_numerical': 0.00404040404040404, 'mean_word_length': 1.83810888252149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2550485', 'n_tokens_mistral': 574, 'n_tokens_neox': 554, 'n_words': 109}