Class: MongoMapper::Pagination::PaginationProxy

Inherits:
BasicObject
Defined in:
lib/mongomapper/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total_entries, current_page, per_page = nil) ⇒ PaginationProxy

Returns a new instance of PaginationProxy.



8
9
10
11
12
# File 'lib/mongomapper/pagination.rb', line 8

def initialize(total_entries, current_page, per_page=nil)
  @total_entries    = total_entries.to_i
  self.per_page     = per_page
  self.current_page = current_page
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



35
36
37
# File 'lib/mongomapper/pagination.rb', line 35

def method_missing(name, *args, &block)
  @subject.send(name, *args, &block)
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



5
6
7
# File 'lib/mongomapper/pagination.rb', line 5

def current_page
  @current_page
end

#per_pageObject Also known as: limit

Returns the value of attribute per_page.



5
6
7
# File 'lib/mongomapper/pagination.rb', line 5

def per_page
  @per_page
end

#subjectObject

Returns the value of attribute subject.



4
5
6
# File 'lib/mongomapper/pagination.rb', line 4

def subject
  @subject
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



5
6
7
# File 'lib/mongomapper/pagination.rb', line 5

def total_entries
  @total_entries
end

Instance Method Details

#next_pageObject



26
27
28
# File 'lib/mongomapper/pagination.rb', line 26

def next_page
  current_page < total_pages ? (current_page + 1) : nil
end

#out_of_bounds?Boolean

Returns:



18
19
20
# File 'lib/mongomapper/pagination.rb', line 18

def out_of_bounds?
  current_page > total_pages
end

#previous_pageObject



22
23
24
# File 'lib/mongomapper/pagination.rb', line 22

def previous_page
  current_page > 1 ? (current_page - 1) : nil
end

#skipObject Also known as: offset



30
31
32
# File 'lib/mongomapper/pagination.rb', line 30

def skip
  (current_page - 1) * per_page
end

#total_pagesObject



14
15
16
# File 'lib/mongomapper/pagination.rb', line 14

def total_pages
  (total_entries / per_page.to_f).ceil
end