deep_unrest 0.1.8 → 0.1.9

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: 39b3378d09d9abba0684d5172640a0aaa0bd349d
4
- data.tar.gz: 3fa3e32ed21c873f62eb035db3a5db2bda801372
3
+ metadata.gz: a9cfbdaef1aa33d938ddab66e9fc2f6ad141fcb3
4
+ data.tar.gz: 304b75b0f0dbadac905ccfd0724266f94bba1fcc
5
5
  SHA512:
6
- metadata.gz: 14224f5153048960a28d33a3dfbd36cc1731f31491b52cfb234c8c01dc7c6e8fa41f48b8cf1cd4c20998d157d8e33133ae6a1b57b17c39832628098c5edeb454
7
- data.tar.gz: 462c92935122bdfd2889862b9af7236e1eaed291b12d2cb84234a081148c4936eaf901fecdb1c0d29f4dbb51f96bbd70b8f5918a2e07ec1050c90ad6580af52d
6
+ metadata.gz: 49b0b0f3783a2031445fd06582c5c21a5e6d30bd2f58cab76c7258106f5f1fe09056ae1a39c87fb9ae5602e1d1a520662a1b631f60ce92570a69eeedd7458eae
7
+ data.tar.gz: ca22b5fc8ba5cdc32c071e97c41a94a5732009c6f84e163763b2243b4f130abc0abf70f2adee66fbe9e5808351f930690548ca6d1d2d60438a18d2c125c822f2
@@ -6,19 +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
9
+ # rails can't deal with array indices in params (converts them to hashes)
10
+ # see https://gist.github.com/bloudermilk/2884947
11
+ def repair_nested_params(obj)
12
+ obj.each do |key, value|
13
+ if value.is_a?(ActionController::Parameters) || value.is_a?(Hash)
14
+ # If any non-integer keys
15
+ if value.keys.find { |k, _| k =~ /\D/ }
16
+ repair_nested_params(value)
17
+ else
18
+ obj[key] = value.values
19
+ value.values.each { |h| repair_nested_params(h) }
20
+ end
21
+ end
16
22
  end
17
23
  end
18
24
 
19
25
  def update
20
26
  redirect = allowed_params[:redirect]
21
- data = format_data(allowed_params[:data])
27
+ data = repair_nested_params(allowed_params[:data])
22
28
  redirect_replace = DeepUnrest.perform_update(data,
23
29
  current_user)
24
30
  resp = {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
5
  end
data/lib/deep_unrest.rb CHANGED
@@ -363,7 +363,8 @@ module DeepUnrest
363
363
  errors.map do |key, values|
364
364
  path_info = parse_error_path(key.to_s)
365
365
  operation = scopes.find do |s|
366
- s[:type] == path_info[:type] && s[:index] == path_info[:idx].to_i
366
+ (s[:type] == path_info[:type].camelize(:lower) &&
367
+ s[:index] == path_info[:idx].to_i)
367
368
  end
368
369
 
369
370
  format_errors(operation, path_info, values)
@@ -390,9 +391,7 @@ module DeepUnrest
390
391
  if errors
391
392
  base_key = "#{record.class.to_s.camelize(:lower).pluralize}[#{i}]"
392
393
  errors.keys.map do |attr|
393
- if record.respond_to? attr
394
- errors["#{base_key}.#{attr}".to_sym] = errors.delete(attr)
395
- end
394
+ errors["#{base_key}.#{attr}".to_sym] = errors.delete(attr)
396
395
  end
397
396
  end
398
397
  errors
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lynn Hurley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-13 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails