<commit_before>module LucidShopify
  module PaginatedResource

    def all( params = {} )
      params = _default_params.merge( params )
      pages  = page_count( params )

      all_pages( pages, params ) unless pages == 0
    end

    # Returns all resources on a given page.
    #
    def page( page, params = {} )
      params = _default_params.merge( params )
      params = params.merge( :page => page )

      r = session.get_resource( _resource, params )

      represent_each r
    end

    private

    def all_pages( pages, params )
      ( 1..pages ).inject( [] ) do |r, page|
        r += page( page, params )
      end
    end

    # Get the total resource count matching +params+ and divide by the given
    # limit (defaults to 50 if none given) per page.
    #
    def page_count( params )
      count = session.get_resource( "#{_resource}/count", params )
      pages = count / params[:limit].to_f || 50.0

      pages.ceil
    end

    def _default_params
      super.merge( :limit => 250 )<commit_msg>Make #all_pages asynchronous.<commit_after>module LucidShopify
  module PaginatedResource

    include LucidClient::Asynchronous

    def all( params = {} )
      params = _default_params.merge( params )
      pages  = page_count( params )

      all_pages( pages, params ) unless pages == 0
    end

    # Returns all resources on a given page.
    #
    def page( page, params = {} )
      params = _default_params.merge( params )
      params = params.merge( :page => page )

      r = session.get_resource( _resource, params )

      represent_each r
    end

    private

    def all_pages( pages, params )
      pages = async_map( 1..pages ) do |page|
        page( page, params )
      end

      pages.flatten
    end

    # Get the total resource count matching +params+ and divide by the given
    # limit (defaults to 50 if none given) per page.
    #
    def page_count( params )
      count = session.get_resource( "#{_resource}/count", params )
      pages = count / params[:limit].to_f || 50.0

      pages.ceil
    end

    def _default_params
      super.merge( :limit => 250 )
{'fraction_non_alphanumeric': 0.09546313799621928, 'fraction_numerical': 0.00945179584120983, 'mean_word_length': 2.3078125, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2879197', 'n_tokens_mistral': 657, 'n_tokens_neox': 612, 'n_words': 204}