Class: Gcloud::Datastore::Cursor

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

Overview

# Cursor

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

Examples:

require "gcloud"

gcloud = Gcloud.new
datastore = gcloud.datastore

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



37
38
39
# File 'lib/gcloud/datastore/cursor.rb', line 37

def initialize cursor
  @cursor = cursor
end

Class Method Details

.from_grpc(grpc) ⇒ Object



69
70
71
72
73
# File 'lib/gcloud/datastore/cursor.rb', line 69

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

Instance Method Details

#<=>(other) ⇒ Object



58
59
60
61
# File 'lib/gcloud/datastore/cursor.rb', line 58

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

#==(other) ⇒ Object



52
53
54
55
# File 'lib/gcloud/datastore/cursor.rb', line 52

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

#inspectObject



47
48
49
# File 'lib/gcloud/datastore/cursor.rb', line 47

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

#to_grpcObject



64
65
66
# File 'lib/gcloud/datastore/cursor.rb', line 64

def to_grpc
  GRPCUtils.decode_bytes(@cursor)
end

#to_sObject

Base64 encoded array of bytes



42
43
44
# File 'lib/gcloud/datastore/cursor.rb', line 42

def to_s
  @cursor
end