Class: Google::Cloud::Datastore::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/datastore/cursor.rb

Overview

# Cursor

Cursor is a point in query results. Cursors are returned in QueryResults.

Examples:

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

query = datastore.query("Task").
  where("done", "=", false)

tasks = datastore.run query
tasks.cursor #=> Cursor

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cursor) ⇒ Cursor

Base64 encoded array of bytes



38
39
40
# File 'lib/google/cloud/datastore/cursor.rb', line 38

def initialize cursor
  @cursor = cursor
end

Class Method Details

.from_grpc(grpc) ⇒ Object



70
71
72
73
74
# File 'lib/google/cloud/datastore/cursor.rb', line 70

def self.from_grpc grpc
  grpc = String grpc
  return nil if grpc.empty?
  new Core::GRPCUtils.encode_bytes(grpc)
end

Instance Method Details

#<=>(other) ⇒ Object



59
60
61
62
# File 'lib/google/cloud/datastore/cursor.rb', line 59

def <=> other
  return -1 unless other.is_a? Cursor
  @cursor <=> other.to_s
end

#==(other) ⇒ Object



53
54
55
56
# File 'lib/google/cloud/datastore/cursor.rb', line 53

def == other
  return false unless other.is_a? Cursor
  @cursor == other.to_s
end

#inspectObject



48
49
50
# File 'lib/google/cloud/datastore/cursor.rb', line 48

def inspect
  "#{self.class}(#{@cursor})"
end

#to_grpcObject



65
66
67
# File 'lib/google/cloud/datastore/cursor.rb', line 65

def to_grpc
  Core::GRPCUtils.decode_bytes(@cursor)
end

#to_sObject

Base64 encoded array of bytes



43
44
45
# File 'lib/google/cloud/datastore/cursor.rb', line 43

def to_s
  @cursor
end