ons-firestore 1.0.2 → 1.1.2

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: 8f758241e0412f8c0b4c72776352c753dd44cea5bcca617bd80efb90baa12829
4
- data.tar.gz: ada12ed5b8d5d1d4ece7cf7812d839dba8f6e55fe592e7ac97e6d00a443565ef
3
+ metadata.gz: 5c03f48298f3f5b0bd96a5f30547076852959de3f6f4980d39ebf2cc580fbe68
4
+ data.tar.gz: 8af0d18d60cf314bf93f53f8647655b7482f472a338480078cedf55362dc22b2
5
5
  SHA512:
6
- metadata.gz: 0f7c7171137c9bc2c6dc8ddf9b96f2ece25c77c3a7cb17031f9a763ac0fea9b41bc797bc3612f884cb5f30513b8a84b01ec69fbe16f9621e9df557e7c7b854fb
7
- data.tar.gz: e37cf44ff5a87a260d98f045a04624eaac0cb441ac910472538d2f36716cab74ea3ad0484511901f2ad688a0a2f703a3f068914939334250250ff4aa6e9e9c15
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
- # 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,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 if value.is_a?(Array)
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
 
@@ -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 = 2
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.2
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-04-27 00:00:00.000000000 Z
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