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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e13381b727ec0a2812128993e0fd888ac8c5acb03f5f5602d098415f33a84132
4
- data.tar.gz: bea7cdd18acdb17ba2fa03bfb1ea47695107b588d76959d19cd6e83ff4fda5e1
3
+ metadata.gz: 9049c0b76b91b92513951f6bfc9b7df860c75743e087740ea0f8a450f2bcc2a0
4
+ data.tar.gz: cab06d69ae63ccf55a625b95f314a8afbbafb9420ed10fd39c4c77fdd57390a2
5
5
  SHA512:
6
- metadata.gz: 7f6449677c53c33f1196d42134a7eb7aed6d0bf926fb1d29bf71cbadd8eaa7a8dde901984f5b9bb664052f7a56ecce7678c634079818c7cf716e8f44cf729596
7
- data.tar.gz: e6451b27a0e51830475f8a9aca4fb3b3502a58debe241ee00d4dfdba760461758c07ae39b7d56286d5382ec5cbe2305a67472d71cc6e228bebdb704706d170ac
6
+ metadata.gz: debc4247cee60152a99a6c9faed9927b804021b0feaa8b5e89fbb06fdff7f3bda229a75ac6610ff8c36a3b2fa76eeb02f17ac889d58c2b2cd21e88561ae93f6b
7
+ data.tar.gz: 84775b8c256e40c9684029980c4c634f6555cfc2a8b91e853fc18ac7deeb6b6eb420287ba5fd3d26fdd0a1b28845a584a0adcc50d0d73ff3b1d574b3908d5e50
@@ -49,7 +49,7 @@ module DeepUnrest
49
49
  end
50
50
 
51
51
  def write
52
- repaired_params = params[:data]
52
+ repaired_params = repair_nested_params(params[:data])
53
53
  data = repaired_params[:data]
54
54
  context = repaired_params[:context] || {}
55
55
  context[:uuid] = request.uuid
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.56'
4
+ VERSION = '0.1.57'
5
5
  end
@@ -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: item.dig(:query, :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
- update_body[:_destroy] = true if item[:scope_type] == :destroy
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
- mappings
220
- .each_with_object({}) do |item, memo|
221
- item[:record]&.errors&.messages&.each do |ar_path, msg|
222
- err_path = format_ar_error_path(item[:addr], ar_path.to_s)
223
- DeepUnrest.set_attr(memo, err_path, msg)
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
- end
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.56
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-12 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails