Class: MongoMapper::Plugins::Pagination::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_mapper/plugins/pagination/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Proxy.



11
12
13
14
15
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 11

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



50
51
52
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 50

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

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



8
9
10
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 8

def current_page
  @current_page
end

#per_pageObject Also known as: limit

Returns the value of attribute per_page.



8
9
10
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 8

def per_page
  @per_page
end

#subjectObject

Returns the value of attribute subject.



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

def subject
  @subject
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



8
9
10
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 8

def total_entries
  @total_entries
end

Instance Method Details

#===(other) ⇒ Object



46
47
48
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 46

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

#next_pageObject



29
30
31
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 29

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

#out_of_bounds?Boolean

Returns:



21
22
23
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 21

def out_of_bounds?
  current_page > total_pages
end

#previous_pageObject



25
26
27
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 25

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

#respond_to?(name, *args, &block) ⇒ Boolean

Returns:



54
55
56
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 54

def respond_to?(name, *args, &block)
  super || @subject.respond_to?(name, *args, &block)
end

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



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

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

#skipObject Also known as: offset



33
34
35
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 33

def skip
  (current_page - 1) * per_page
end

#total_pagesObject



17
18
19
# File 'lib/mongo_mapper/plugins/pagination/proxy.rb', line 17

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