Class: Mongoid::Scroll::Base64EncodedCursor
- Inherits:
-
BaseCursor
- Object
- BaseCursor
- Mongoid::Scroll::Base64EncodedCursor
- Defined in:
- lib/mongoid/scroll/base64_encoded_cursor.rb
Overview
Allows to serializer/deserialize the cursor using RFC 4648
Instance Attribute Summary
Attributes inherited from BaseCursor
#direction, #field_name, #field_type, #include_current, #tiebreak_id, #type, #value
Instance Method Summary collapse
-
#initialize(value, options = {}) ⇒ Base64EncodedCursor
constructor
A new instance of Base64EncodedCursor.
- #to_s ⇒ Object
Methods inherited from BaseCursor
#criteria, from_record, #sort_options
Constructor Details
#initialize(value, options = {}) ⇒ Base64EncodedCursor
Returns a new instance of Base64EncodedCursor.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mongoid/scroll/base64_encoded_cursor.rb', line 8 def initialize(value, = {}) = () if value begin parsed = ::JSON.parse(::Base64.strict_decode64(value)) rescue StandardError raise Mongoid::Scroll::Errors::InvalidBase64CursorError.new(cursor: value) end super(parse_field_value(parsed['field_type'], parsed['field_name'], parsed['value']), { field_type: parsed['field_type'], field_name: parsed['field_name'], direction: parsed['direction'], include_current: parsed['include_current'], tiebreak_id: parsed['tiebreak_id'] && !parsed['tiebreak_id'].empty? ? BSON::ObjectId.from_string(parsed['tiebreak_id']) : nil, type: parsed['type'].try(:to_sym) }) else super(nil, ) end end |
Instance Method Details
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mongoid/scroll/base64_encoded_cursor.rb', line 29 def to_s Base64.strict_encode64({ value: transform_field_value(field_type, field_name, value), field_type: field_type.to_s, field_name: field_name, direction: direction, include_current: include_current, tiebreak_id: tiebreak_id && tiebreak_id.to_s, type: type }.to_json) end |