ons-firestore 1.0.2 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ons-firestore/firestore.rb +35 -17
- data/lib/ons-firestore/version.rb +1 -1
- 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: 5c03f48298f3f5b0bd96a5f30547076852959de3f6f4980d39ebf2cc580fbe68
|
4
|
+
data.tar.gz: 8af0d18d60cf314bf93f53f8647655b7482f472a338480078cedf55362dc22b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a6a540662de8767427f296d377e08b3ca359a30751f5047fdb076147bb8b050f22ec70b7aecbdf665fb45df33553bbf48d489b6cc04ffcfaa2c3243b767d027
|
7
|
+
data.tar.gz: d0fc5a3f590acb665517dd02e7927d66b40192e82ef0656dcaf468e82a1e2bd99b6faa521d87741b7b7d7f2c8a5931fa442b6705e2f2e2537d9452b097c3f115
|
@@ -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 [Enumerator] 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?
|
@@ -61,8 +80,7 @@ class Firestore
|
|
61
80
|
if data.is_a?(Hash)
|
62
81
|
hash_data = {}
|
63
82
|
data.each do |key, value|
|
64
|
-
hash_data[key] = value
|
65
|
-
hash_data[key] = value.map(&:to_h) unless value.is_a?(Array)
|
83
|
+
hash_data[key] = value.class.method_defined?(:to_h) ? value.map(&:to_h) : value
|
66
84
|
end
|
67
85
|
end
|
68
86
|
|
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.
|
4
|
+
version: 1.1.2
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-firestore
|