module FirestoreODM::Collection
Public Instance Methods
collection(root = nil)
click to toggle source
Returns the collection used by the model. @param root [Google::Cloud::Firestore::DocumentReference] @return [Google::Cloud::Firestore::CollectionReference] the collection.
# File lib/firestore-odm/collection.rb, line 8 def collection root = nil (root or Google::Cloud::Firestore.new).collection @path end
create(opts = {})
click to toggle source
Creates a document. @param opts [Hash] a hash with options. @yield [doc] @return [FirestoreODM::Document] the document.
# 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 = {})
click to toggle source
Creates a document with an specific id. @param id [String] the document id. @param opts [Hash] @yield [doc] @return [FirestoreODM::Document] the document.
# 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 = {})
click to toggle source
Gets a document. @param id [String] @param opts [Hash] @return [FirestoreODM::Document] the document.
# 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)
click to toggle source
Sets the collection name. @param name [String, Symbol] the collection name.
# File lib/firestore-odm/collection.rb, line 14 def path name @path = name return end