Sha256: d90380a4e04d0624956121fd8148b78d63e261f71497bfbe9f98ef9bef710923

Contents?: true

Size: 594 Bytes

Versions: 6

Compression:

Stored size: 594 Bytes

Contents

# frozen_string_literal: true

module Care::AutoFinder
  #
  # Содержит методы для пагинации коллекции
  #
  # @example
  #   class Finder
  #     include Paginateble
  #
  #     attr_reader :params
  #
  #     def call
  #       params = { page: 2, limit: 10 }
  #       by_page(Document)
  #     end
  #   end
  #
  module Paginateble
    DEFAULT_LIMIT = 100

    def by_page(items)
      params[:page].present? ? items.page(params[:page]).per(params[:limit] || DEFAULT_LIMIT) : items
    end

    def paginate(items)
      by_page(items)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
care-0.1.6 lib/care/auto_finder/paginateble.rb
care-0.1.5 lib/care/auto_finder/paginateble.rb
care-0.1.4 lib/care/auto_finder/paginateble.rb
care-0.1.3 lib/care/auto_finder/paginateble.rb
care-0.1.1 lib/care/auto_finder/paginateble.rb
care-0.1.0 lib/care/auto_finder/paginateble.rb