Class: Mongoid::Scroll::BaseCursor
- Inherits:
-
Object
- Object
- Mongoid::Scroll::BaseCursor
- Defined in:
- lib/mongoid/scroll/base_cursor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#field_name ⇒ Object
Returns the value of attribute field_name.
-
#field_type ⇒ Object
Returns the value of attribute field_type.
-
#include_current ⇒ Object
Returns the value of attribute include_current.
-
#tiebreak_id ⇒ Object
Returns the value of attribute tiebreak_id.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #criteria ⇒ Object
-
#initialize(value, options = {}) ⇒ BaseCursor
constructor
A new instance of BaseCursor.
- #sort_options ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value, options = {}) ⇒ BaseCursor
Returns a new instance of BaseCursor.
6 7 8 9 10 11 12 13 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 6 def initialize(value, = {}) @value = value @tiebreak_id = [:tiebreak_id] @field_type = [:field_type] @field_name = [:field_name] @direction = [:direction] || 1 @include_current = [:include_current] || false end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
4 5 6 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 4 def direction @direction end |
#field_name ⇒ Object
Returns the value of attribute field_name.
4 5 6 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 4 def field_name @field_name end |
#field_type ⇒ Object
Returns the value of attribute field_type.
4 5 6 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 4 def field_type @field_type end |
#include_current ⇒ Object
Returns the value of attribute include_current.
4 5 6 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 4 def include_current @include_current end |
#tiebreak_id ⇒ Object
Returns the value of attribute tiebreak_id.
4 5 6 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 4 def tiebreak_id @tiebreak_id end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 4 def value @value end |
Class Method Details
.from_record(record, options) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 41 def from_record(record, ) cursor = new(nil, ) record_value = record.respond_to?(cursor.field_name) ? record.send(cursor.field_name) : record[cursor.field_name] cursor.value = cursor.send(:parse_field_value, cursor.field_type, cursor.field_name, record_value) cursor.tiebreak_id = record['_id'] cursor end |
Instance Method Details
#criteria ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 15 def criteria mongo_value = value.class.mongoize(value) if value cursor_criteria = { field_name => { compare_direction => mongo_value } } if mongo_value tiebreak_criteria = { field_name => mongo_value, :_id => { tiebreak_compare_direction => tiebreak_id } } if mongo_value && tiebreak_id cursor_selector = if Mongoid::Compatibility::Version.mongoid6_or_newer? Mongoid::Criteria::Queryable::Selector.new else Origin::Selector.new end cursor_selector['$or'] = [cursor_criteria, tiebreak_criteria].compact if cursor_criteria || tiebreak_criteria cursor_selector.__evolve_object_id__ end |
#sort_options ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 28 def { field_type: field_type, field_name: field_name, direction: direction } end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 36 def to_s raise NotImplementedError.new(:to_s) end |