require 'mr/query' module MR class FakeQuery attr_reader :results, :count alias :results! :results alias :count! :count def initialize(results) @results = results || [] @count = @results.size end def first @results.first end alias :first! :first def paged(page_num = nil, page_size = nil) FakePagedQuery.new(self, page_num, page_size) end end class FakePagedQuery < FakeQuery attr_reader :page_num, :page_size, :page_offset, :total_count alias :total_count! :total_count def initialize(query, page_num, page_size) @page_num = MR::PagedQuery::PageNumber.new(page_num) @page_size = MR::PagedQuery::PageSize.new(page_size) @page_offset = MR::PagedQuery::PageOffset.new(@page_num, @page_size) @unpaged_results = query.results.dup @total_count = @unpaged_results.size @has_next_page = (@page_offset + @page_size) < @total_count super(@unpaged_results.dup[@page_offset, @page_size]) end def has_next_page? @has_next_page end def is_last_page? !self.has_next_page? end end end