Module: FirestoreODM::Collection
- Included in:
- Model
- Defined in:
- lib/firestore-odm/collection.rb
Instance Method Summary collapse
-
#collection(root = nil) ⇒ Google::Cloud::Firestore::CollectionReference
Returns the collection used by the model.
-
#create(opts = {}) {|doc| ... } ⇒ FirestoreODM::Document
Creates a document.
-
#create_with_id(id, opts = {}) {|doc| ... } ⇒ FirestoreODM::Document
Creates a document with an specific id.
-
#from_id(id, opts = {}) ⇒ FirestoreODM::Document
Gets a document.
-
#path(name) ⇒ Object
Sets the collection name.
Instance Method Details
#collection(root = nil) ⇒ Google::Cloud::Firestore::CollectionReference
Returns the collection used by the model.
8 9 10 |
# File 'lib/firestore-odm/collection.rb', line 8 def collection root = nil (root or Google::Cloud::Firestore.new).collection @path end |
#create(opts = {}) {|doc| ... } ⇒ FirestoreODM::Document
Creates a document.
23 24 25 26 27 28 |
# File 'lib/firestore-odm/collection.rb', line 23 def create opts = {}, &block block.call o = self.new doc = collection(opts[:relative_to]).add o.changes self.new doc end |
#create_with_id(id, opts = {}) {|doc| ... } ⇒ FirestoreODM::Document
Creates a document with an specific id.
35 36 37 38 39 40 41 |
# File 'lib/firestore-odm/collection.rb', line 35 def create_with_id id, opts = {}, &block block.call o = self.new doc = collection(opts[:relative_to]).doc id doc.create o.changes self.from_id id, opts end |
#from_id(id, opts = {}) ⇒ FirestoreODM::Document
Gets a document.
47 48 49 50 |
# File 'lib/firestore-odm/collection.rb', line 47 def from_id id, opts = {} doc = collection(opts[:relative_to]).doc id self.new doc end |
#path(name) ⇒ Object
Sets the collection name.
14 15 16 17 |
# File 'lib/firestore-odm/collection.rb', line 14 def path name @path = name return end |