deep_unrest 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/deep_unrest/version.rb +1 -1
- data/lib/deep_unrest.rb +14 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e805e8e946507f8e9e3c7efc8699f45da9aeb6d1
|
4
|
+
data.tar.gz: 24dbd8cd92cac4fd34ce96c0ee7234a20773ccd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e565d06c10f0d524d1f4e940ec125702704d28722ed86e8db399af34aacd08c5a2639e5fef76e544dbfd0809a515e9e6ee0ab7abcfa0bc178aa1439c6d774983
|
7
|
+
data.tar.gz: 957d530761f55e9aa9b9392efa38181a4627354c6f38f129a3c8c83cc4992c47bf078adb11785b9d053a82b8525c1f9c6699ba298263a35448bc86919cb955fd
|
data/lib/deep_unrest/version.rb
CHANGED
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,
|
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
|
-
|
294
|
-
|
295
|
-
|
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
|