Class: MongoidPagingToken::PagingToken
- Inherits:
-
Object
- Object
- MongoidPagingToken::PagingToken
- Defined in:
- lib/mongoid_paging_token/paging_token.rb
Instance Attribute Summary collapse
-
#criteria ⇒ Object
readonly
Returns the value of attribute criteria.
Instance Method Summary collapse
- #can_page? ⇒ Boolean
-
#initialize(criteria) ⇒ PagingToken
constructor
A new instance of PagingToken.
- #next_page_criteria ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(criteria) ⇒ PagingToken
Returns a new instance of PagingToken.
5 6 7 |
# File 'lib/mongoid_paging_token/paging_token.rb', line 5 def initialize(criteria) @criteria = criteria end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
4 5 6 |
# File 'lib/mongoid_paging_token/paging_token.rb', line 4 def criteria @criteria end |
Instance Method Details
#can_page? ⇒ Boolean
21 22 23 |
# File 'lib/mongoid_paging_token/paging_token.rb', line 21 def can_page? !!(sorts && limit) && limit > 0 && limit == entries.size end |
#next_page_criteria ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mongoid_paging_token/paging_token.rb', line 9 def next_page_criteria if sorts.keys.size > 2 raise NotImplementedError, 'paging not supported for more than two sorted fields' end if one_field_sort? one_field_sort_criteria else two_field_sort_criteria end end |
#to_s ⇒ Object
25 26 27 28 |
# File 'lib/mongoid_paging_token/paging_token.rb', line 25 def to_s return nil unless can_page? CGI.escape(Base64.encode64(Marshal.dump(next_page_criteria))) end |