Class: Mongoid::Scroll::Cursor

Inherits:
BaseCursor show all
Defined in:
lib/mongoid/scroll/cursor.rb

Instance Attribute Summary

Attributes inherited from BaseCursor

#direction, #field_name, #field_type, #include_current, #tiebreak_id, #value

Instance Method Summary collapse

Methods inherited from BaseCursor

#criteria, from_record, #sort_options

Constructor Details

#initialize(value = nil, options = {}) ⇒ Cursor

Returns a new instance of Cursor.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mongoid/scroll/cursor.rb', line 4

def initialize(value = nil, options = {})
  options = extract_field_options(options)
  raise ArgumentError.new 'Missing options[:field_name] and/or options[:field_type].' unless options
  if value
    parts = value.split(':') if value
    unless parts && parts.length >= 2
      raise Mongoid::Scroll::Errors::InvalidCursorError.new(cursor: value)
    end
    value = parse_field_value(
      options[:field_type],
      options[:field_name],
      parts[0...-1].join(':')
    )
    options[:tiebreak_id] = BSON::ObjectId.from_string(parts[-1])
    super value, options
  else
    super nil, options
  end
end

Instance Method Details

#to_sObject



24
25
26
27
28
29
30
31
32
# File 'lib/mongoid/scroll/cursor.rb', line 24

def to_s
  tiebreak_id ? [
    transform_field_value(
      field_type,
      field_name,
      value
    ), tiebreak_id
  ].join(':') : nil
end