Sha256: 5c7d609feddf7a477030bb45f32938ae8440f41c5282841317c44b267fd80f41

Contents?: true

Size: 969 Bytes

Versions: 31

Compression:

Stored size: 969 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
        return Workarea.config.per_page if params[:per_page].blank?

        tmp = params[:per_page].to_i
        tmp > 0 ? tmp : 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.27 app/queries/workarea/search/pagination.rb
workarea-core-3.5.26 app/queries/workarea/search/pagination.rb
workarea-core-3.4.45 app/queries/workarea/search/pagination.rb
workarea-core-3.5.25 app/queries/workarea/search/pagination.rb
workarea-core-3.5.23 app/queries/workarea/search/pagination.rb
workarea-core-3.4.44 app/queries/workarea/search/pagination.rb
workarea-core-3.5.22 app/queries/workarea/search/pagination.rb
workarea-core-3.4.43 app/queries/workarea/search/pagination.rb
workarea-core-3.5.21 app/queries/workarea/search/pagination.rb
workarea-core-3.4.42 app/queries/workarea/search/pagination.rb
workarea-core-3.5.20 app/queries/workarea/search/pagination.rb
workarea-core-3.4.41 app/queries/workarea/search/pagination.rb
workarea-core-3.5.19 app/queries/workarea/search/pagination.rb
workarea-core-3.4.40 app/queries/workarea/search/pagination.rb
workarea-core-3.5.18 app/queries/workarea/search/pagination.rb
workarea-core-3.4.39 app/queries/workarea/search/pagination.rb
workarea-core-3.5.17 app/queries/workarea/search/pagination.rb
workarea-core-3.4.38 app/queries/workarea/search/pagination.rb
workarea-core-3.5.16 app/queries/workarea/search/pagination.rb
workarea-core-3.4.37 app/queries/workarea/search/pagination.rb