deep-cloning 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deep_cloning.rb +16 -5
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ae70dc1594781e54e95ed136d33d28e6e9a441d09e71e876042726afa6bcf7
|
4
|
+
data.tar.gz: 64f20a6d57d21e9f01fc3b6b4f002699e2910b009074e6158745e0c538cc32c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b9fd95aed554c41cb24b5abd381fe54f8f77e18fae9bcdbf967b448bfbfc24c2bcef81eb57eac2f41a336b6ae3231c62bb99458d2d926c918c7496ca30e5af1
|
7
|
+
data.tar.gz: b205973f081b28dc6e1293ad59fd46f8f682862b2247444a93a0c144535e3d17570536d058e16157cfbd7726e8f05eaba649a04a4fa8d7f7ea75328d24cfe7e6
|
data/lib/deep_cloning.rb
CHANGED
@@ -3,11 +3,12 @@ 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.4'.freeze
|
7
7
|
def initialize(root, opts = { except: [], save_root: true })
|
8
8
|
@root = root
|
9
9
|
@opts = opts
|
10
10
|
@opts[:source] = []
|
11
|
+
@must_ignore = []
|
11
12
|
end
|
12
13
|
|
13
14
|
def replicate
|
@@ -19,7 +20,7 @@ module DeepCloning
|
|
19
20
|
yield(@root, clone, :before_save) if block_given?
|
20
21
|
clone.save if clone.new_record? # avoid save again if saved on block
|
21
22
|
yield(@root, clone, :after_save) if block_given?
|
22
|
-
raise clone.errors.full_messages.join(', ') if clone.errors.any?
|
23
|
+
raise "#{clone.class} - #{clone.errors.full_messages.join(', ')}" if clone.errors.any?
|
23
24
|
@opts[clone.class.name] = { @root.id => clone }
|
24
25
|
end
|
25
26
|
leafs(@root).each do |cell|
|
@@ -33,7 +34,7 @@ module DeepCloning
|
|
33
34
|
end
|
34
35
|
unless @cell
|
35
36
|
ap @opts[:source].map { |s| "#{s.id} - #{s.class.name}" }
|
36
|
-
raise
|
37
|
+
raise "Cannot duplicate the Hierarchy. You must ignore: #{@must_ignore.join(', ')}"
|
37
38
|
end
|
38
39
|
@opts[:source] -= [@cell]
|
39
40
|
|
@@ -71,6 +72,14 @@ module DeepCloning
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
75
|
+
def safe_child?(child, parent)
|
76
|
+
!child.respond_to?("#{parent.name}_id".to_sym) or
|
77
|
+
child.send("#{parent.name}_id").nil? or
|
78
|
+
@opts[parent.class_name][child.send("#{parent.name}_id")] or
|
79
|
+
parent.class_name.in? @opts[:except]
|
80
|
+
# replicated parent?
|
81
|
+
end
|
82
|
+
|
74
83
|
# Need to check the relations instead the models only
|
75
84
|
def walk?(cell)
|
76
85
|
parents(cell.class).map do |p|
|
@@ -84,9 +93,11 @@ module DeepCloning
|
|
84
93
|
end
|
85
94
|
else
|
86
95
|
@opts[p.class_name] = {} unless @opts[p.class_name]
|
87
|
-
|
96
|
+
safe_child = safe_child?(cell, p)
|
97
|
+
@must_ignore << p.class_name unless safe_child
|
98
|
+
safe_child
|
88
99
|
end
|
89
|
-
end.
|
100
|
+
end.all?(&:present?)
|
90
101
|
end
|
91
102
|
|
92
103
|
def leafs(cell)
|
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nilton Vasques
|
8
|
+
- Victor Cordeiro
|
9
|
+
- Beatriz Fagundes
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2019-02-18 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: minitest
|
@@ -55,6 +57,8 @@ dependencies:
|
|
55
57
|
description: DeepCloning is a gem that is able to replicate a set of records in depth
|
56
58
|
email:
|
57
59
|
- nilton.vasques@gmail.com
|
60
|
+
- victorcorcos@gmail.com
|
61
|
+
- beatrizsfslima@gmail.com
|
58
62
|
executables: []
|
59
63
|
extensions: []
|
60
64
|
extra_rdoc_files: []
|