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.
-
#type ⇒ Object
Returns the value of attribute type.
-
#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 14 15 16 |
# 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 @type = [:type] || :next raise Mongoid::Scroll::Errors::UnsupportedTypeError.new(type: @type) unless i[previous next].include?(@type) 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 |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 4 def type @type 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
40 41 42 43 44 45 46 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 40 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
18 19 20 21 22 23 24 25 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 18 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 = Mongoid::Criteria::Queryable::Selector.new cursor_selector['$or'] = [cursor_criteria, tiebreak_criteria].compact if cursor_criteria || tiebreak_criteria cursor_selector.__evolve_object_id__ end |
#sort_options ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 27 def { field_type: field_type, field_name: field_name, direction: direction } end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/mongoid/scroll/base_cursor.rb', line 35 def to_s raise NotImplementedError.new(:to_s) end |