class Google::Cloud::Firestore::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}.
@example
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
Public Class Methods
@private New DocumentChange
from a Google::Cloud::Firestore::DocumentSnapshot
object.
# File lib/google/cloud/firestore/document_change.rb, line 114 def self.from_doc doc, old_index, new_index new.tap do |s| s.instance_variable_set :@doc, doc s.instance_variable_set :@old_index, old_index s.instance_variable_set :@new_index, new_index end end
Public Instance Methods
Determines whether the document was added.
@return [Boolean] Whether the document was added.
# File lib/google/cloud/firestore/document_change.rb, line 71 def added? type == :added end
The document snapshot object for the data.
@return [DocumentSnapshot] document snapshot.
# File lib/google/cloud/firestore/document_change.rb, line 50 def doc @doc end
Determines whether the document was modified.
@return [Boolean] Whether the document was modified.
# File lib/google/cloud/firestore/document_change.rb, line 80 def modified? type == :modified end
The index in the documents array after the change.
@return [Integer, nil] The new index
# File lib/google/cloud/firestore/document_change.rb, line 107 def new_index @new_index end
The index in the documents array prior to the change.
@return [Integer, nil] The old index
# File lib/google/cloud/firestore/document_change.rb, line 98 def old_index @old_index end
Determines whether the document was removed.
@return [Boolean] Whether the document was removed.
# File lib/google/cloud/firestore/document_change.rb, line 89 def removed? type == :removed end
The type of change (':added', ':modified', or ':removed').
@return [Symbol] The type of change.
# 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