Class: Google::Cloud::Firestore::DocumentChange

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/firestore/document_change.rb

Overview

DocumentChange

A DocumentChange object represents a change to the document matching a query. It contains the document affected and the type of change that occurred (added, modifed, or removed).

See Query#listen and QuerySnapshot#changes.

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Create a query
query = firestore.col(:cities).order(:population, :desc)

listener = query.listen do |snapshot|
  puts "The query snapshot has #{snapshot.docs.count} documents "
  puts "and has #{snapshot.changes.count} changes."
end

# When ready, stop the listen operation and close the stream.
listener.stop

Instance Method Summary collapse

Instance Method Details

#added?Boolean

Determines whether the document was added.

Returns:

  • (Boolean)

    Whether the document was added.



71
72
73
# File 'lib/google/cloud/firestore/document_change.rb', line 71

def added?
  type == :added
end

#docDocumentSnapshot Also known as: document

The document snapshot object for the data.

Returns:



50
51
52
# File 'lib/google/cloud/firestore/document_change.rb', line 50

def doc
  @doc
end

#modified?Boolean

Determines whether the document was modified.

Returns:

  • (Boolean)

    Whether the document was modified.



80
81
82
# File 'lib/google/cloud/firestore/document_change.rb', line 80

def modified?
  type == :modified
end

#new_indexInteger?

The index in the documents array after the change.

Returns:

  • (Integer, nil)

    The new index



107
108
109
# File 'lib/google/cloud/firestore/document_change.rb', line 107

def new_index
  @new_index
end

#old_indexInteger?

The index in the documents array prior to the change.

Returns:

  • (Integer, nil)

    The old index



98
99
100
# File 'lib/google/cloud/firestore/document_change.rb', line 98

def old_index
  @old_index
end

#removed?Boolean

Determines whether the document was removed.

Returns:

  • (Boolean)

    Whether the document was removed.



89
90
91
# File 'lib/google/cloud/firestore/document_change.rb', line 89

def removed?
  type == :removed
end

#typeSymbol

The type of change (':added', ':modified', or ':removed').

Returns:

  • (Symbol)

    The type of change.



60
61
62
63
64
# File 'lib/google/cloud/firestore/document_change.rb', line 60

def type
  return :removed if @new_index.nil?
  return :added if @old_index.nil?
  :modified
end