deep-cloning 0.1.2 → 0.1.3
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_cloning.rb +9 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be606e88796177c306fc3363c7d5f4deec819e51ff807841dc35b0de9e7aee7
|
4
|
+
data.tar.gz: 2b3810d7c27cb615cffd85dfce75a9ecabcf4724f9b24d956e08497aa106b0c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea68292929342892c413452f369aedf9336e5892180ba3e5e4c964f9f450d2b78b4899c6b053129f86b8952b12c2a00161aeb2b425dd8b541a191baa0a1de72f
|
7
|
+
data.tar.gz: 607ddbf9fab6837e11691c83790a25952e519a2757ea8b7dad7fb793691a7142d4eead6d230416117d66329949f8161e07b1392855bb6bbd80e0592c96a6ef13
|
data/lib/deep_cloning.rb
CHANGED
@@ -3,10 +3,11 @@ require 'active_record'
|
|
3
3
|
module DeepCloning
|
4
4
|
# This is the main class responsible to evaluate the equations
|
5
5
|
class Clone
|
6
|
-
VERSION = '0.1.
|
6
|
+
VERSION = '0.1.3'.freeze
|
7
7
|
def initialize(root, opts = { except: [], save_root: true })
|
8
8
|
@root = root
|
9
9
|
@opts = opts
|
10
|
+
@opts[:source] = []
|
10
11
|
end
|
11
12
|
|
12
13
|
def replicate
|
@@ -21,7 +22,9 @@ module DeepCloning
|
|
21
22
|
raise clone.errors.full_messages.join(', ') if clone.errors.any?
|
22
23
|
@opts[clone.class.name] = { @root.id => clone }
|
23
24
|
end
|
24
|
-
|
25
|
+
leafs(@root).each do |cell|
|
26
|
+
@opts[:source] << cell if block_given? and not yield(cell, cell, :skip?)
|
27
|
+
end
|
25
28
|
|
26
29
|
while @opts[:source].any?
|
27
30
|
@cell = @opts[:source].detect do |n|
|
@@ -36,10 +39,8 @@ module DeepCloning
|
|
36
39
|
|
37
40
|
@opts[@cell.class.name] = {} unless @opts[@cell.class.name]
|
38
41
|
next if @opts[@cell.class.name][@cell.id] # already cloned?
|
39
|
-
skip = false
|
40
|
-
skip = yield(@cell, clone, :skip?) if block_given?
|
41
42
|
|
42
|
-
|
43
|
+
unless @cell.class.name.in?(@opts[:except])
|
43
44
|
clone = @cell.dup
|
44
45
|
parents(clone.class).each do |belongs_to|
|
45
46
|
old_id = clone.send("#{belongs_to.name}_id")
|
@@ -62,7 +63,9 @@ module DeepCloning
|
|
62
63
|
raise "#{clone.class} - #{clone.errors.full_messages.join(', ')}" if clone.errors.any?
|
63
64
|
@opts[clone.class.name][@cell.id] = clone
|
64
65
|
end
|
65
|
-
|
66
|
+
leafs(@cell).each do |cell|
|
67
|
+
@opts[:source] << cell if block_given? and not yield(cell, cell, :skip?)
|
68
|
+
end
|
66
69
|
leafs_statuses["#{@cell.class.name}_#{@cell.id}"] = true
|
67
70
|
end
|
68
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep-cloning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nilton Vasques
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|