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.
See Google::Cloud::Firestore::DocumentReference#get, Google::Cloud::Firestore::DocumentReference#listen, Query#get, Query#listen, and QuerySnapshot#docs.
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.
| 241 242 243 244 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 241 def created_at return nil if missing? Convert. grpc.create_time end | 
#data ⇒ Hash? Also known as: fields
Retrieves the document data. When the document exists the data hash is
frozen and will not allow any changes. When the document does not
exist nil will be returned.
| 157 158 159 160 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 157 def data return nil if missing? @data ||= Convert.fields_to_hash(grpc.fields, ref.client).freeze end | 
#document_id ⇒ String
The document identifier for the document snapshot.
| 72 73 74 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 72 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.
| 81 82 83 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 81 def document_path ref.document_path end | 
#exists? ⇒ Boolean
Determines whether the document exists.
| 288 289 290 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 288 def exists? !missing? end | 
#get(field_path) ⇒ Object Also known as: []
Retrieves the document data.
| 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 211 def get field_path unless field_path.is_a? FieldPath field_path = FieldPath.parse field_path end nodes = field_path.fields.map(&:to_sym) return ref if nodes == [:__name__] selected_data = data nodes.each do |node| unless selected_data.is_a? Hash err_msg = "#{field_path.formatted_string} is not " \ "contained in the data" raise ArgumentError, err_msg end selected_data = selected_data[node] end selected_data end | 
#missing? ⇒ Boolean
Determines whether the document is missing.
| 307 308 309 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 307 def missing? grpc.nil? end | 
#parent ⇒ CollectionReference
The collection the document snapshot belongs to.
| 132 133 134 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 132 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.
| 268 269 270 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 268 def read_at @read_at end | 
#ref ⇒ DocumentReference Also known as: reference
The document reference object for the data.
| 111 112 113 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 111 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.
| 255 256 257 258 | # File 'lib/google/cloud/firestore/document_snapshot.rb', line 255 def updated_at return nil if missing? Convert. grpc.update_time end |