class MR::PagedQuery
Attributes
page_num[R]
page_offset[R]
page_size[R]
Public Class Methods
new(query, page_num = nil, page_size = nil)
click to toggle source
Calls superclass method
MR::Query::new
# File lib/mr/query.rb, line 71 def initialize(query, page_num = nil, page_size = nil) @page_num = PageNumber.new(page_num) @page_size = PageSize.new(page_size) @page_offset = PageOffset.new(@page_num, @page_size) @unpaged_relation = query.relation.dup relation = query.relation.offset(@page_offset).limit(@page_size) super query.model_class, relation end
Public Instance Methods
has_next_page?()
click to toggle source
# File lib/mr/query.rb, line 92 def has_next_page? @has_next_page ||= (self.page_offset + self.page_size) < self.total_count end
is_last_page?()
click to toggle source
# File lib/mr/query.rb, line 96 def is_last_page? !self.has_next_page? end
total_count()
click to toggle source
# File lib/mr/query.rb, line 81 def total_count @total_count ||= total_count! end
total_count!()
click to toggle source
This isn't done in the `initialize` because it runs a query (which is expensive) and should only be done when it's needed. If it's never used then, running it in the `initialize` would be wasteful.
# File lib/mr/query.rb, line 88 def total_count! @total_count = total_count_relation.count end
Private Instance Methods
total_count_relation()
click to toggle source
# File lib/mr/query.rb, line 102 def total_count_relation @total_count_relation ||= CountRelation.new(@unpaged_relation) end