Class: Google::Cloud::Firestore::DocumentSnapshot
- Inherits:
-
Object
- Object
- Google::Cloud::Firestore::DocumentSnapshot
- Defined in:
- lib/google/cloud/firestore/document_snapshot.rb
Overview
DocumentSnapshot
A document snapshot object is an immutable representation for a document in a Cloud Firestore database.
The snapshot can reference a non-existing document.
Access collapse
-
#parent ⇒ CollectionReference
The collection the document snapshot belongs to.
-
#ref ⇒ DocumentReference
(also: #reference)
The document reference object for the data.
Data collapse
-
#data ⇒ Hash
(also: #fields)
Retrieves the document data.
-
#get(field_path) ⇒ Object
(also: #[])
Retrieves the document data.
Instance Method Summary collapse
-
#created_at ⇒ Time
(also: #create_time)
The time at which the document was created.
-
#document_id ⇒ String
The document identifier for the document snapshot.
-
#document_path ⇒ String
A string representing the path of the document, relative to the document root of the database.
-
#exists? ⇒ Boolean
Determines whether the document exists.
-
#missing? ⇒ Boolean
Determines whether the document is missing.
-
#read_at ⇒ Time
(also: #read_time)
The time at which the document was read.
-
#updated_at ⇒ Time
(also: #update_time)
The time at which the document was last changed.
Instance Method Details
#created_at ⇒ Time Also known as: create_time
The time at which the document was created.
This value increases when a document is deleted then recreated.
217 218 219 220 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 217 def created_at return nil if missing? Convert. grpc.create_time end |
#data ⇒ Hash Also known as: fields
Retrieves the document data.
135 136 137 138 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 135 def data return nil if missing? Convert.fields_to_hash grpc.fields, ref.client end |
#document_id ⇒ String
The document identifier for the document snapshot.
52 53 54 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 52 def document_id ref.document_id end |
#document_path ⇒ String
A string representing the path of the document, relative to the document root of the database.
61 62 63 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 61 def document_path ref.document_path end |
#exists? ⇒ Boolean
Determines whether the document exists.
264 265 266 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 264 def exists? !missing? end |
#get(field_path) ⇒ Object Also known as: []
Retrieves the document data.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 189 def get field_path unless field_path.is_a? FieldPath field_path = FieldPath.parse field_path end nodes = field_path.fields.map(&:to_sym) selected_data = data nodes.each do |node| unless selected_data.is_a? Hash fail ArgumentError, "#{field_path.formatted_string} is not contained in the data" end selected_data = selected_data[node] end selected_data end |
#missing? ⇒ Boolean
Determines whether the document is missing.
283 284 285 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 283 def missing? grpc.nil? end |
#parent ⇒ CollectionReference
The collection the document snapshot belongs to.
112 113 114 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 112 def parent ref.parent end |
#read_at ⇒ Time Also known as: read_time
The time at which the document was read.
This value is set even if the document does not exist.
244 245 246 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 244 def read_at @read_at end |
#ref ⇒ DocumentReference Also known as: reference
The document reference object for the data.
91 92 93 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 91 def ref @ref end |
#updated_at ⇒ Time Also known as: update_time
The time at which the document was last changed.
This value is initally set to the created_at
on document creation,
and increases each time the document is updated.
231 232 233 234 |
# File 'lib/google/cloud/firestore/document_snapshot.rb', line 231 def updated_at return nil if missing? Convert. grpc.update_time end |