rails_deep_copy 0.0.2 → 0.0.5
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/rails_deep_copy/version.rb +1 -1
- data/lib/rails_deep_copy.rb +4 -2
- 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: 32f436a3503aa45c13e3775c4f2680b50f6ae4d4
|
4
|
+
data.tar.gz: d3289c42f5dfbf6900c8c73e4e9a97659895ee4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4d06a012de451061a08f7d7958ae9d23a1d2ed1d015f9fb217a1fb7ddde292c631974811b43ce6bbd79b0a2a1c4301c9d05a4027ff4b86b12721cbc5d826749
|
7
|
+
data.tar.gz: 016dd1df64b1e25913f883686fa2de63eea17a01eaff28c6da149ec15c4c42357c5ea27851e78049de3125f8cf6b0b723b4e33f9ea0fd94a8e4215f90c07b105
|
data/lib/rails_deep_copy.rb
CHANGED
@@ -12,12 +12,12 @@ module RailsDeepCopy
|
|
12
12
|
@skip_validations = options[:skip_validations] || true
|
13
13
|
@id_hash = options[:id_hash] || {}
|
14
14
|
@changes.merge!(@id_hash)
|
15
|
+
@duplicated_objects = options.fetch(:duplicated_objects, [])
|
15
16
|
setup_associations
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.create(object_to_duplicate, options = {})
|
19
20
|
Duplicate.new(object_to_duplicate, options).execute
|
20
|
-
@new_object
|
21
21
|
end
|
22
22
|
|
23
23
|
def default_associations
|
@@ -88,15 +88,17 @@ module RailsDeepCopy
|
|
88
88
|
def execute
|
89
89
|
implement_new_object_differences
|
90
90
|
@new_object.save(:validate => validate?) && update_id_hash
|
91
|
+
@duplicated_objects << @new_object
|
91
92
|
associations.each do |association|
|
92
93
|
objects = [@object_to_duplicate.send(association.name)].flatten
|
93
94
|
objects.each do |obj|
|
94
95
|
# recursively create child objects and assign IDs
|
95
|
-
Duplicate.create(obj, id_hash: id_hash)
|
96
|
+
Duplicate.create(obj, id_hash: id_hash, duplicated_objects: @duplicated_objects)
|
96
97
|
end
|
97
98
|
end
|
98
99
|
# done with children - remove ID from ID hash
|
99
100
|
remove_id_from_id_hash
|
101
|
+
@duplicated_objects.first
|
100
102
|
end
|
101
103
|
|
102
104
|
end
|