deep-cloning 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/deep_cloning.rb +9 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49fe856693c2852e697f2daa2b4e754baae413d4fa824d0d78be0e644edc25f3
4
- data.tar.gz: e17a02eae597e1f5588b05adda3990dbb5ca7526e9b6ec124e57983c33382e27
3
+ metadata.gz: 8be606e88796177c306fc3363c7d5f4deec819e51ff807841dc35b0de9e7aee7
4
+ data.tar.gz: 2b3810d7c27cb615cffd85dfce75a9ecabcf4724f9b24d956e08497aa106b0c6
5
5
  SHA512:
6
- metadata.gz: 33e46e86566a06479886c1d1a4c23b992affd82e0792e83ee319d01d93aab31c25d3464658a614b01c0c4a69cc560b44837a459e72619eedf654d8a850608ead
7
- data.tar.gz: e841d75867ddbe8ec399055acd46cdfd596eac020047f1b34ba846e189669c4da34f55159a48331b735efe1245737414f2c6da86d62189e939a825c815bc53be
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.2'.freeze
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
- @opts[:source] = leafs(@root)
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
- if not @cell.class.name.in?(@opts[:except]) and not skip
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
- @opts[:source] += leafs(@cell)
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.2
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-07 00:00:00.000000000 Z
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest