deep_unrest 0.1.56 → 0.1.57
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/deep_unrest/application_controller.rb +1 -1
- data/lib/deep_unrest/version.rb +1 -1
- data/lib/deep_unrest/write.rb +19 -10
- 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: 9049c0b76b91b92513951f6bfc9b7df860c75743e087740ea0f8a450f2bcc2a0
|
4
|
+
data.tar.gz: cab06d69ae63ccf55a625b95f314a8afbbafb9420ed10fd39c4c77fdd57390a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: debc4247cee60152a99a6c9faed9927b804021b0feaa8b5e89fbb06fdff7f3bda229a75ac6610ff8c36a3b2fa76eeb02f17ac889d58c2b2cd21e88561ae93f6b
|
7
|
+
data.tar.gz: 84775b8c256e40c9684029980c4c634f6555cfc2a8b91e853fc18ac7deeb6b6eb420287ba5fd3d26fdd0a1b28845a584a0adcc50d0d73ff3b1d574b3908d5e50
|
data/lib/deep_unrest/version.rb
CHANGED
data/lib/deep_unrest/write.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
module DeepUnrest
|
4
4
|
module Write
|
5
|
-
def self.get_scope_type(item)
|
5
|
+
def self.get_scope_type(item, path)
|
6
|
+
return :index if DeepUnrest.plural?(path)
|
6
7
|
return :destroy if item[:destroy]
|
7
8
|
return :show if item[:readOnly] || item[:attributes].blank?
|
8
9
|
return :create if item[:id] && DeepUnrest.temp_id?(item[:id].to_s)
|
@@ -19,7 +20,7 @@ module DeepUnrest
|
|
19
20
|
[{ klass: k.singularize.classify.constantize,
|
20
21
|
policy: "#{k.singularize.classify}Policy".constantize,
|
21
22
|
resource: "#{k.singularize.classify}Resource".constantize,
|
22
|
-
scope_type: get_scope_type(v),
|
23
|
+
scope_type: get_scope_type(v, path),
|
23
24
|
addr: resource_addr,
|
24
25
|
key: k.camelize(:lower),
|
25
26
|
uuid: uuid,
|
@@ -98,12 +99,16 @@ module DeepUnrest
|
|
98
99
|
def self.build_mutation_bodies(mappings)
|
99
100
|
mappings.each_with_object({}) do |item, memo|
|
100
101
|
# TODO: use pkey instead of "id"
|
102
|
+
id = item.dig(:query, :id)
|
103
|
+
next if id.blank?
|
104
|
+
|
101
105
|
next_attrs = (item.dig(:query, :attributes) || {})
|
102
106
|
.deep_symbolize_keys
|
103
|
-
update_body = { id:
|
107
|
+
update_body = { id: id,
|
104
108
|
deep_unrest_query_uuid: item.dig(:query, :uuid),
|
105
109
|
**DeepUnrest.deep_underscore_keys(next_attrs) }
|
106
|
-
|
110
|
+
|
111
|
+
update_body[:_destroy] = true if item.dig(:query, :destroy)
|
107
112
|
DeepUnrest.set_attr(memo, item[:ar_addr].clone, update_body)
|
108
113
|
if item[:ar_addr].size == 1
|
109
114
|
item[:mutate] = memo.fetch(*item[:ar_addr])
|
@@ -136,6 +141,7 @@ module DeepUnrest
|
|
136
141
|
end
|
137
142
|
end
|
138
143
|
when :destroy
|
144
|
+
id = item.dig(:query, :id)
|
139
145
|
model = item[:klass].find(id)
|
140
146
|
resource = item[:resource].new(model, context)
|
141
147
|
resource.run_callbacks :remove do
|
@@ -216,13 +222,15 @@ module DeepUnrest
|
|
216
222
|
end
|
217
223
|
|
218
224
|
def self.map_ar_errors_to_param_keys(mappings)
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
225
|
+
DeepUnrest.deep_camelize_keys(
|
226
|
+
mappings
|
227
|
+
.each_with_object({}) do |item, memo|
|
228
|
+
item[:record]&.errors&.messages&.each do |ar_path, msg|
|
229
|
+
err_path = format_ar_error_path(item[:addr], ar_path.to_s)
|
230
|
+
DeepUnrest.set_attr(memo, err_path, msg)
|
231
|
+
end
|
224
232
|
end
|
225
|
-
|
233
|
+
)
|
226
234
|
end
|
227
235
|
|
228
236
|
def self.write(ctx, params, user)
|
@@ -282,3 +290,4 @@ module DeepUnrest
|
|
282
290
|
end
|
283
291
|
end
|
284
292
|
end
|
293
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_unrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.57
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lynn Hurley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|