<commit_before>module ActiveModel
  class Serializer
    class Adapter
      class JsonApi < Adapter
        class PaginationLinks
          FIRST_PAGE = 1

          attr_reader :collection

          def initialize(collection)
            raise_unless_any_gem_installed
            @collection = collection
          end

          def serializable_hash(options = {})
            pages_from.each_with_object({}) do |(key, value), hash|
              query_parameters = options.fetch(:query_parameters) { {} }
              params = query_parameters.merge(page: { number: value, size: collection.size }).to_query

              hash[key] = "#{url(options)}?#{params}"
            end
          end

          private

          def pages_from
            return {} if collection.total_pages == FIRST_PAGE

            {}.tap do |pages|
              unless collection.current_page == FIRST_PAGE
                pages[:first] = FIRST_PAGE
                pages[:prev]  = collection.current_page - FIRST_PAGE
              end

              unless collection.current_page == collection.total_pages
                pages[:next] = collection.current_page + FIRST_PAGE
                pages[:last] = collection.total_pages
              end
            end
          end

          def raise_unless_any_gem_installed
            return if defined?(WillPaginate) || defined?(Kaminari)
            raise "AMS relies on either Kaminari or WillPaginate." +
              "Please install either dependency by adding one of those to your Gemfile"
          end

          def url(options)
            self_link = options.fetch(:links) {{}}
            self_link.fetch(:self) {} ? options[:links][:self] : options[:original_url]
          end
        end
      end
    end
  end
end
<commit_msg>fix message on raise of pagination links class<commit_after>module ActiveModel
  class Serializer
    class Adapter
      class JsonApi < Adapter
        class PaginationLinks
          FIRST_PAGE = 1

          attr_reader :collection

          def initialize(collection)
            raise_unless_any_gem_installed
            @collection = collection
          end

          def serializable_hash(options = {})
            pages_from.each_with_object({}) do |(key, value), hash|
              query_parameters = options.fetch(:query_parameters) { {} }
              params = query_parameters.merge(page: { number: value, size: collection.size }).to_query

              hash[key] = "#{url(options)}?#{params}"
            end
          end

          private

          def pages_from
            return {} if collection.total_pages == FIRST_PAGE

            {}.tap do |pages|
              unless collection.current_page == FIRST_PAGE
                pages[:first] = FIRST_PAGE
                pages[:prev]  = collection.current_page - FIRST_PAGE
              end

              unless collection.current_page == collection.total_pages
                pages[:next] = collection.current_page + FIRST_PAGE
                pages[:last] = collection.total_pages
              end
            end
          end

          def raise_unless_any_gem_installed
            return if defined?(WillPaginate) || defined?(Kaminari)
            raise <<-EOF
            AMS relies on either Kaminari or WillPaginate for pagination.
            Please install either dependency by adding one of those to your Gemfile.
            EOF
          end

          def url(options)
            self_link = options.fetch(:links) {{}}
            self_link.fetch(:self) {} ? options[:links][:self] : options[:original_url]
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07707076247942951, 'fraction_numerical': 0.0005485463521667581, 'mean_word_length': 1.7483044461190655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '7391226', 'n_tokens_mistral': 950, 'n_tokens_neox': 890, 'n_words': 233}