ons-firestore 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfcc9c616b8d8e3309c90dcd33395a620ccdd4d51a88b0fdfe817df3f5559a9e
4
- data.tar.gz: 25695e1400af224f5ac2e690c1330d55939bdac2bda22bdf37705e8b396e9e83
3
+ metadata.gz: 7071e0cea0d0adb25db556b56c07e5e3db7373efb6568d80fa86ad3de7f0553a
4
+ data.tar.gz: fa2f124217f08065cbeec384fa2d2c896c4b6c935dde744861a3b03d10e77019
5
5
  SHA512:
6
- metadata.gz: 73943d0336742113d2b666b3efcf8e4a2af6690bc4810f4f7e3c11b2cc00c0e79a89db08aae1cf4f61a094a689ab80c31fe6dfe6da1201811c6f69d4e18c4507
7
- data.tar.gz: 86c4ef0555351bd5c86e1621f4eec4024dcb43fd628f6621c376f5bae9aeb2ed3032e650f997f5d758c614e6d8eec67c8f7eadfa9c9213494a8c90178730c46c
6
+ metadata.gz: 5d67f09a82059d39cd90ef7e5b153562d68e71e27f1b379748bb139bd498c58f4ea4c548b4f5132a44ea666e7ef4f7f19ba356fe65d55b9937a8e8b3601266fa
7
+ data.tar.gz: 7098b9941d613ca972ca4078987e306b7d7ad2d01a2d1a9a4b821e0efa88a40da0f664103caaa41713875c788cfb2c059cd9be20b6a136190c2a277a23e590c2
@@ -10,10 +10,8 @@ class Firestore
10
10
 
11
11
  # Constructor that initialises the Firestore client.
12
12
  #
13
- # Params:
14
- # - project_id: The ID of the GCP project containing the Firestore database.
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
- # Reads a Firestore document.
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
- # Params:
27
- # - collection_name: The name of the Firestore collection containing the document.
28
- # - document_name: The name of the Firestore document.
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
- # An Argument error is raised if collection_name or document_name are nil.
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
- # Params:
46
- # - collection_name: The name of the Firestore collection containing the document.
47
- # - document_name: The name of the Firestore document.
48
- # - data: Data to save to the Firestore document.
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,7 +80,8 @@ 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.respond_to?(:to_h) ? value.map(&:to_h) : value
83
+ hash_data[key] = value if value.is_a?(Array)
84
+ hash_data[key] = value.map(&:to_h) unless value.is_a?(Array)
65
85
  end
66
86
  end
67
87
 
@@ -3,7 +3,7 @@
3
3
  module ONSFirestore
4
4
  module Version
5
5
  MAJOR = 1
6
- MINOR = 0
6
+ MINOR = 1
7
7
  TINY = 1
8
8
  end
9
9
  VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
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.1
4
+ version: 1.1.1
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-04-27 00:00:00.000000000 Z
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