Class: MongoMapper::Pagination::PaginationProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_mapper/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.



10
11
12
13
14
# File 'lib/mongo_mapper/pagination.rb', line 10

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



49
50
51
# File 'lib/mongo_mapper/pagination.rb', line 49

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

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



7
8
9
# File 'lib/mongo_mapper/pagination.rb', line 7

def current_page
  @current_page
end

#per_pageObject Also known as: limit

Returns the value of attribute per_page.



7
8
9
# File 'lib/mongo_mapper/pagination.rb', line 7

def per_page
  @per_page
end

#subjectObject

Returns the value of attribute subject.



6
7
8
# File 'lib/mongo_mapper/pagination.rb', line 6

def subject
  @subject
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



7
8
9
# File 'lib/mongo_mapper/pagination.rb', line 7

def total_entries
  @total_entries
end

Instance Method Details

#===(other) ⇒ Object



45
46
47
# File 'lib/mongo_mapper/pagination.rb', line 45

def ===(other)
  other === subject
end

#next_pageObject



28
29
30
# File 'lib/mongo_mapper/pagination.rb', line 28

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

#out_of_bounds?Boolean

Returns:



20
21
22
# File 'lib/mongo_mapper/pagination.rb', line 20

def out_of_bounds?
  current_page > total_pages
end

#previous_pageObject



24
25
26
# File 'lib/mongo_mapper/pagination.rb', line 24

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

#send(method, *args, &block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/mongo_mapper/pagination.rb', line 37

def send(method, *args, &block)
  if respond_to?(method)
    super
  else
    subject.send(method, *args, &block)
  end
end

#skipObject Also known as: offset



32
33
34
# File 'lib/mongo_mapper/pagination.rb', line 32

def skip
  (current_page - 1) * per_page
end

#total_pagesObject



16
17
18
# File 'lib/mongo_mapper/pagination.rb', line 16

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