deep_unrest 0.1.15 → 0.1.16

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: 6399b9cf607bb71db3f29983c64bc875e51ad88a
4
- data.tar.gz: 43ba25e40fa2e101623686090c4a7969bab2e372
3
+ metadata.gz: e805e8e946507f8e9e3c7efc8699f45da9aeb6d1
4
+ data.tar.gz: 24dbd8cd92cac4fd34ce96c0ee7234a20773ccd1
5
5
  SHA512:
6
- metadata.gz: e6ed340e24a1949b13c2690ca40bffc0f6cdc1e96c6005e97c033c7b68bdeeaa086db38d5a6ea24a701a6f2e8c8098e45ed050a8002bae97925f03c41316cac9
7
- data.tar.gz: dc3bd0f748165261d9431004e7a622069756b1de57ba35a18c111f57417dc451c66c3d416c1906742212e0ebcbe1dba5446ccfe1daa6073a140321460bf0466c
6
+ metadata.gz: e565d06c10f0d524d1f4e940ec125702704d28722ed86e8db399af34aacd08c5a2639e5fef76e544dbfd0809a515e9e6ee0ab7abcfa0bc178aa1439c6d774983
7
+ data.tar.gz: 957d530761f55e9aa9b9392efa38181a4627354c6f38f129a3c8c83cc4992c47bf078adb11785b9d053a82b8525c1f9c6699ba298263a35448bc86919cb955fd
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.15'
4
+ VERSION = '0.1.16'
5
5
  end
data/lib/deep_unrest.rb CHANGED
@@ -5,11 +5,14 @@ require 'deep_unrest/engine'
5
5
  # workaronud for rails bug with association indices.
6
6
  # see https://github.com/rails/rails/pull/24728
7
7
  module ActiveRecord
8
+ # monkey-patch
8
9
  module AutosaveAssociation
9
10
  # Returns the record for an association collection that should be validated
10
11
  # or saved. If +autosave+ is +false+ only new records will be returned,
11
12
  # unless the parent is/was a new record itself.
12
- def associated_records_to_validate_or_save(association, new_record, autosave)
13
+ def associated_records_to_validate_or_save(association,
14
+ new_record,
15
+ autosave)
13
16
  if new_record || autosave
14
17
  association && association.target
15
18
  else
@@ -290,9 +293,16 @@ module DeepUnrest
290
293
  case v
291
294
  when Array
292
295
  h = v.each_with_object({}) do |item, memo|
293
- memo[item[:id]] ||= {}
294
- memo[item[:id]].deeper_merge(item)
295
- merge_siblings!(item)
296
+ if item.respond_to?(:key?) && item.key?(:id)
297
+ # this is a nested resource. merge as such
298
+ memo[item[:id]] ||= {}
299
+ memo[item[:id]].deeper_merge(item)
300
+ merge_siblings!(item)
301
+ else
302
+ # otherwise this is just a normal array
303
+ idx = memo.keys.size
304
+ memo[idx] = item
305
+ end
296
306
  end
297
307
  mutations[k] = h.values
298
308
  when Hash
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.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lynn Hurley