ons-firestore 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ons-firestore/firestore.rb +34 -15
- data/lib/ons-firestore/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0077852086ffe77e35e89820a68feae7bc2711f74f0727dca47587344c8d0a41'
|
4
|
+
data.tar.gz: 3fa7333f538ac6f6ed5038d8c6190a02473c7f451ca2dfe04b4e5d151ec27ceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f01fb9331db325667ac3e60f6e1a9310f05cc3fdd0025462913bfc5c328191fefc1deb5b2de921aacb48377ade65cb090af4ac622b493b14c5a8df49d74bcedf
|
7
|
+
data.tar.gz: cf2ca0fb7c3fd1093c56d12388174e726133d1e8df59fe8da319d97e18d1cd089c6aaba7e31ed8eee17591d960aaa7f84bdd16f9825106c3de8a69dee80791cb
|
@@ -10,10 +10,8 @@ class Firestore
|
|
10
10
|
|
11
11
|
# Constructor that initialises the Firestore client.
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# An Argument error is raised if project_id is nil.
|
13
|
+
# @param project_id [String] the ID of the GCP project containing the Firestore database
|
14
|
+
# @raise [ArgumentError] if project_id is nil
|
17
15
|
def initialize(project_id)
|
18
16
|
raise ArgumentError.new('project_id cannot be nil') if project_id.nil?
|
19
17
|
|
@@ -21,13 +19,36 @@ class Firestore
|
|
21
19
|
@client = Google::Cloud::Firestore.new
|
22
20
|
end
|
23
21
|
|
24
|
-
#
|
22
|
+
# Returns all Firestore documents within a collection.
|
23
|
+
#
|
24
|
+
# @param collection_name [String] the name of the Firestore collection containing the documents
|
25
|
+
# @return [Enumberator] list of documents within the collection
|
26
|
+
# @raise [ArgumentError] if collection_name is nil
|
27
|
+
def all_documents(collection_name)
|
28
|
+
raise ArgumentError.new('collection_name cannot be nil') if collection_name.nil?
|
29
|
+
|
30
|
+
@client.col(collection_name).list_documents.all
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns a reference to a Firestore document.
|
25
34
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
35
|
+
# @param collection_name [String] the name of the Firestore collection containing the document
|
36
|
+
# @param document_name [String] the name of the Firestore document
|
37
|
+
# @return [Google::Cloud::Firestore::DocumentReference] reference to the document
|
38
|
+
# @raise [ArgumentError] if collection_name or document_name are nil
|
39
|
+
def document_reference(collection_name, document_name)
|
40
|
+
raise ArgumentError.new('collection_name cannot be nil') if collection_name.nil?
|
41
|
+
raise ArgumentError.new('document_name cannot be nil') if document_name.nil?
|
42
|
+
|
43
|
+
@client.col(collection_name).doc(document_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Reads the +data+ key within a Firestore document.
|
29
47
|
#
|
30
|
-
#
|
48
|
+
# @param collection_name [String] the name of the Firestore collection containing the document
|
49
|
+
# @param document_name [String] the name of the Firestore document
|
50
|
+
# @return [Object] document data
|
51
|
+
# @raise [ArgumentError] if collection_name or document_name are nil
|
31
52
|
def read_document(collection_name, document_name)
|
32
53
|
raise ArgumentError.new('collection_name cannot be nil') if collection_name.nil?
|
33
54
|
raise ArgumentError.new('document_name cannot be nil') if document_name.nil?
|
@@ -42,12 +63,10 @@ class Firestore
|
|
42
63
|
# The passed data are saved under a +data+ key within the document.
|
43
64
|
# A timestamp at which the operation occurred is saved under the +updated+ key within the document.
|
44
65
|
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# An Argument error is raised if collection_name or document_name are nil.
|
66
|
+
# @param collection_name [String] the name of the Firestore collection containing the document
|
67
|
+
# @param document_name [String] the name of the Firestore document
|
68
|
+
# @param data [Object] data to save to the Firestore document
|
69
|
+
# @raise [ArgumentError] if collection_name or document_name are nil
|
51
70
|
def save_document(collection_name, document_name, data)
|
52
71
|
raise ArgumentError.new('collection_name cannot be nil') if collection_name.nil?
|
53
72
|
raise ArgumentError.new('document_name cannot be nil') if document_name.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ons-firestore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Topley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-firestore
|