act_as_fire_record_beta 0.0.1 → 0.0.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d8ee306c4e6bccb39cdd7cfa2c84dbe0a89c13a011354619bdf99ed1151227b
|
4
|
+
data.tar.gz: 5b969ad0910739a3d4d0e67e03e28ff7d0e292b60df0dabf9e837fc3030c90f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8aaa747059a1deb309124fd69e180dc1b08789d361a5cd86a4bc6274361d6dcc90a4d5f51448f4ebb408ad865138be49d3b3dab1b90c85fa08b77590316b3df
|
7
|
+
data.tar.gz: 37673dc337b3bcbd127d434a03ba0e8c2c50577233546ccb05a234a3270fe1aa5718f116395086150a13977d4d703ec442d9cfe179aa21d245d770c46df6fab3
|
@@ -2,35 +2,29 @@ module Google
|
|
2
2
|
module Cloud
|
3
3
|
module Firestore
|
4
4
|
class Query
|
5
|
-
def
|
6
|
-
find_many(limit: 1, &block)[0]
|
7
|
-
end
|
8
|
-
|
9
|
-
def find_one!(&block)
|
10
|
-
find_one(&block) || raise(ActiveRecord::RecordNotFound)
|
11
|
-
end
|
12
|
-
|
13
|
-
def find_many(limit: nil, &block)
|
5
|
+
def get_records(limit: nil)
|
14
6
|
scope = limit ? limit(limit) : self
|
15
7
|
scope.get.map do |data|
|
16
|
-
|
17
|
-
record = model_lass.to_instance(data)
|
18
|
-
block.call(record) if block
|
19
|
-
record
|
8
|
+
fire_record_class.to_instance(data)
|
20
9
|
end
|
21
10
|
end
|
22
11
|
|
23
12
|
def destroy_all
|
24
|
-
|
13
|
+
doc_refs = get_records.map(&:doc_ref)
|
14
|
+
fire_record_class.delete_in_batch(doc_refs)
|
15
|
+
end
|
16
|
+
|
17
|
+
def first(limit = 1)
|
18
|
+
records = get_records(limit: limit)
|
19
|
+
limit == 1 ? records[0] : records
|
25
20
|
end
|
26
21
|
|
27
22
|
def exists?
|
28
|
-
!!
|
23
|
+
!!first
|
29
24
|
end
|
30
25
|
|
31
|
-
def
|
32
|
-
|
33
|
-
limit == 1 ? records[0] : records
|
26
|
+
def fire_record_class
|
27
|
+
@_fire_record_class ||= ActAsFireRecordBeta.class_mapping[query.from[0].collection_id]
|
34
28
|
end
|
35
29
|
end
|
36
30
|
end
|
@@ -23,6 +23,8 @@ module ActAsFireRecordBeta
|
|
23
23
|
attribute :created_at, :time
|
24
24
|
attribute :updated_at, :time
|
25
25
|
|
26
|
+
attr_accessor :doc_ref
|
27
|
+
|
26
28
|
ActAsFireRecordBeta.class_mapping[collection_name_with_env] = self
|
27
29
|
end
|
28
30
|
|
@@ -43,8 +45,8 @@ module ActAsFireRecordBeta
|
|
43
45
|
client.doc("#{collection_name_with_env}/#{id}")
|
44
46
|
end
|
45
47
|
|
46
|
-
def all
|
47
|
-
col.
|
48
|
+
def all
|
49
|
+
col.get_records
|
48
50
|
end
|
49
51
|
|
50
52
|
def find(id)
|
@@ -55,14 +57,14 @@ module ActAsFireRecordBeta
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def find_by(param)
|
58
|
-
raise ArgumentError, "param size should 1: #{param}" unless param.size == 1
|
60
|
+
raise ArgumentError, "param size should be 1: #{param}" unless param.size == 1
|
59
61
|
field, value = param.to_a.flatten
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
end
|
63
|
+
where(field, :==, value).first
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
+
def find_by!(param)
|
67
|
+
find_by(param) || raise(ActiveRecord::RecordNotFound)
|
66
68
|
end
|
67
69
|
|
68
70
|
def where(field, operator, value)
|
@@ -74,7 +76,7 @@ module ActAsFireRecordBeta
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def first(limit = 1)
|
77
|
-
records = col.
|
79
|
+
records = col.get_records(limit: limit)
|
78
80
|
limit == 1 ? records[0] : records
|
79
81
|
end
|
80
82
|
|
@@ -91,7 +93,20 @@ module ActAsFireRecordBeta
|
|
91
93
|
end
|
92
94
|
|
93
95
|
def destroy_all
|
94
|
-
col.list_documents
|
96
|
+
delete_in_batch(col.list_documents)
|
97
|
+
end
|
98
|
+
|
99
|
+
def delete_in_batch(doc_refs)
|
100
|
+
max_batch_size = 500
|
101
|
+
nested_doc_refs = doc_refs.each_slice(max_batch_size)
|
102
|
+
firestore = Google::Cloud::Firestore.new
|
103
|
+
nested_doc_refs.each do |doc_refs|
|
104
|
+
firestore.batch do |b|
|
105
|
+
doc_refs.each do |doc_ref|
|
106
|
+
b.delete(doc_ref)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
95
110
|
end
|
96
111
|
|
97
112
|
def save_params(record)
|
@@ -107,7 +122,7 @@ module ActAsFireRecordBeta
|
|
107
122
|
@_firestore_attributes.each do |key|
|
108
123
|
params[key] = data[key]
|
109
124
|
end
|
110
|
-
new(params)
|
125
|
+
new(params).tap { |record| record.doc_ref = data }
|
111
126
|
end
|
112
127
|
|
113
128
|
private
|
@@ -165,6 +180,13 @@ module ActAsFireRecordBeta
|
|
165
180
|
true
|
166
181
|
end
|
167
182
|
|
183
|
+
# Override
|
184
|
+
def inspect
|
185
|
+
hash = attributes.transform_keys(&:to_sym)
|
186
|
+
hash_text = hash.to_s[1..-2]
|
187
|
+
"#<#{self.class} #{hash_text}>"
|
188
|
+
end
|
189
|
+
|
168
190
|
private
|
169
191
|
|
170
192
|
def save_params
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act_as_fire_record_beta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Junichi Ito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -69,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
69
|
requirements:
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
72
|
+
version: 3.0.0
|
73
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
75
|
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.2.33
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: ActiveRecord like interface for Firestore
|