deep_unrest 0.1.6 → 0.1.7

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
  SHA1:
3
- metadata.gz: 06c3e91ce0d55f72657cbbc336204ee4e9892d55
4
- data.tar.gz: 94d86685379dd5dd778234d59d0d46973e774b6d
3
+ metadata.gz: ae3d92d31f39fb9850caad832917df453a3d1c9b
4
+ data.tar.gz: e9d68cb90229eb52728e9889fcee1a0e02391b08
5
5
  SHA512:
6
- metadata.gz: 240d5d75be4343f354d1255ecc8eb1a0f3a5218b5162c433e2260677c44d7407bc62309e0f7b2a3b5469a2ea27a3834758eef6a31c88f6cc2b9f3c90fe1b0ee0
7
- data.tar.gz: e50e934116f6095b25b8dea4f3139bc4c203c4f3999b1b622fb329bab0df0c234ceca63fe5050523133b7e518ecb5d73fc78beb213f05a6fdae3113ceae7d6d2
6
+ metadata.gz: 8e3334ab48073acdfafd5958d876cadca7cae37e4a4d0a1845bcbc2f2d4dbfbb30894698c85ca14bb370d7c3c0aa0dd8c20d01611a8d0397df0ddacc2836d0b1
7
+ data.tar.gz: cefde02eb26d6e4bfd6dcb21ec4942e4edfc3c7fea2c0b278d5fb95902b102ea768c5b424d8d009b5ce9e724f6847f664f661ac4e451ca97899eff0b6e2db583
@@ -6,16 +6,25 @@ module DeepUnrest
6
6
  { current_user: current_user }
7
7
  end
8
8
 
9
+
10
+ # multipart data will be an array-like hash
11
+ def format_data(data)
12
+ if data.respond_to? :values
13
+ data.values
14
+ else
15
+ data
16
+ end
17
+ end
18
+
9
19
  def update
10
20
  redirect = allowed_params[:redirect]
11
- redirect_replace = DeepUnrest.perform_update(allowed_params[:data],
21
+ data = format_data(allowed_params[:data])
22
+ redirect_replace = DeepUnrest.perform_update(data,
12
23
  current_user)
13
- if redirect
14
- response.headers.merge! update_auth_header
15
- redirect_to redirect_replace.call(redirect)
16
- else
17
- render json: {}, status: 200
18
- end
24
+ resp = {}
25
+ resp[:redirect] = redirect_replace.call(redirect) if redirect
26
+ response.headers.merge! update_auth_header
27
+ render json: resp, status: 200
19
28
  rescue DeepUnrest::Unauthorized => err
20
29
  render json: err.message, status: 403
21
30
  rescue DeepUnrest::UnpermittedParams => err
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
data/lib/deep_unrest.rb CHANGED
@@ -384,6 +384,20 @@ module DeepUnrest
384
384
  end
385
385
  end
386
386
 
387
+ def self.format_error_keys(res, i)
388
+ record = res[:record]
389
+ errors = record&.errors&.messages
390
+ if errors
391
+ base_key = "#{record.class.to_s.underscore.pluralize}[#{i}]"
392
+ errors.keys.map do |attr|
393
+ if record.respond_to? attr
394
+ errors["#{base_key}.#{attr}".to_sym] = errors.delete(attr)
395
+ end
396
+ end
397
+ end
398
+ errors
399
+ end
400
+
387
401
  def self.perform_update(params, user)
388
402
  # identify requested scope(s)
389
403
  scopes = collect_all_scopes(params)
@@ -401,10 +415,9 @@ module DeepUnrest
401
415
  results = mutate(mutations, user).flatten
402
416
 
403
417
  # check results for errors
404
- errors = results.map { |res| res[:record] }
418
+ errors = results.each_with_index
419
+ .map { |res, i| format_error_keys(res, i) }
405
420
  .compact
406
- .map(&:errors)
407
- .map(&:messages)
408
421
  .reject(&:empty?)
409
422
  .compact
410
423
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_unrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lynn Hurley