Sha256: 92510620d2d5157cfdd87ffde617f1adc88e0bdc6c08afbc24b9d04ffaff76d3

Contents?: true

Size: 877 Bytes

Versions: 31

Compression:

Stored size: 877 Bytes

Contents

module Workarea
  module Search
    module Pagination
      def page
        tmp = params[:page].present? ? params[:page].to_i : 1
        tmp > 0 ? tmp : 1
      end

      def per_page
        params[:per_page].presence || Workarea.config.per_page
      end

      def size
        super || per_page
      end

      def from
        size * (page - 1)
      end

      def results
        @paged_results ||= PagedArray.from(
          super,
          page,
          per_page,
          total
        )
      end

      def each_by(by, &block)
        i = 0

        while (results = get_each_by_results(by, i)) && results.present?
          results.each { |result| yield(result) }
          i += 1
        end
      end

      private

      def get_each_by_results(by, i)
        self.class.new(params.merge(page: i + 1, per_page: by)).results
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
workarea-core-3.5.9 app/queries/workarea/search/pagination.rb
workarea-core-3.4.31 app/queries/workarea/search/pagination.rb
workarea-core-3.5.8 app/queries/workarea/search/pagination.rb
workarea-core-3.4.30 app/queries/workarea/search/pagination.rb
workarea-core-3.5.7 app/queries/workarea/search/pagination.rb
workarea-core-3.4.29 app/queries/workarea/search/pagination.rb
workarea-core-3.5.6 app/queries/workarea/search/pagination.rb
workarea-core-3.4.28 app/queries/workarea/search/pagination.rb
workarea-core-3.5.5 app/queries/workarea/search/pagination.rb
workarea-core-3.4.27 app/queries/workarea/search/pagination.rb
workarea-core-3.5.4 app/queries/workarea/search/pagination.rb
workarea-core-3.4.26 app/queries/workarea/search/pagination.rb
workarea-core-3.5.3 app/queries/workarea/search/pagination.rb
workarea-core-3.4.25 app/queries/workarea/search/pagination.rb
workarea-core-3.5.2 app/queries/workarea/search/pagination.rb
workarea-core-3.4.24 app/queries/workarea/search/pagination.rb
workarea-core-3.5.1 app/queries/workarea/search/pagination.rb
workarea-core-3.4.23 app/queries/workarea/search/pagination.rb
workarea-core-3.4.22 app/queries/workarea/search/pagination.rb
workarea-core-3.5.0 app/queries/workarea/search/pagination.rb