Sha256: 264712f4823c025aad91bfa65486a65a8e069545c976c53ea8226b7a8b5c0b6f

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

# encoding: utf-8

module DataMapper
  module Resource
    module ClassMethods
      # @since 0.0.2
      def paginate(pagenum = 1, options = Hash.new)
        pagenum = 1 if pagenum.nil?
        page = self.page(pagenum.to_i, options)
        Page.current = page
        offset = page.number(:db) * page.per_page
        self.all(offset: offset, limit: page.per_page, order: [:updated_at.desc]).all(options)
      end

      # @since 0.0.2
      def page(current, options = Hash.new)
        per_page = defined?(PER_PAGE) ? PER_PAGE : 10
        # the count options are very important
        # Product.count vs. Product.count(online: true)
        Page.new(current: current, count: self.count(options), per_page: per_page)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rango-0.0.4 lib/rango/contrib/pagination/adapters/datamapper.rb