Sha256: 4a3c10a052f50f11bd609ebb6d3a33f33de3b69dbcbc1ecdb558025f4a993195

Contents?: true

Size: 758 Bytes

Versions: 3

Compression:

Stored size: 758 Bytes

Contents

#*************************************************************************************
# Insert the method paginate in a Mongoid model. This method will be use the limit
# the number of results returned by a query.
#*************************************************************************************
module NeatPages::Implants::MongoidCriteriaImplant
  def paginate(current)
    if current
      current.set_total_items self.count

      raise NeatPages::OutOfBound if current.out_of_bound?

      return self.offset(current.offset).limit(current.limit)
    else
      raise NeatPages::Uninitalized, 'You need to initialize the pagination'
    end
  end
end

Mongoid::Criteria.send :include, NeatPages::Implants::MongoidCriteriaImplant if defined? Mongoid

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neat-pages-1.0.2 lib/neat_pages/implants/mongoid_implant.rb
neat-pages-1.0.1 lib/neat_pages/implants/mongoid_implant.rb
neat-pages-1.0.0 lib/neat_pages/implants/mongoid_implant.rb