full_clone 0.0.10 → 1.0.0
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/README.md +3 -2
- data/full_clone.gemspec +1 -1
- data/lib/full_clone/array.rb +17 -18
- data/lib/full_clone/hash.rb +17 -18
- data/lib/full_clone/object.rb +26 -13
- data/lib/full_clone/struct.rb +17 -18
- data/lib/full_clone/use_clone.rb +4 -0
- data/lib/full_clone/use_self.rb +8 -1
- data/lib/full_clone/version.rb +1 -1
- data/rakefile.rb +5 -0
- data/reek.txt +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8385b340fff44a74cd9d7331d4736d3cfcb6ef3e
|
4
|
+
data.tar.gz: 83549c5119a63deafacb4b8f4c22cff46d8569ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ae12b3a5d8825a09973da6264d044612f421b682aa242cabb4efd428f89f119970a19284b796079fe5f17bb876cd11c352b3512c92f4482ee89f799333eecdf
|
7
|
+
data.tar.gz: 43352b509b4bc3ee5eb6c47b48cdf194b9bc9eb0523f54126acbb79151bf77f9d47045c4e5059c438a97f1be7097cba9fffc8835ed0ac5ea3b7acdb8e7b77116
|
data/README.md
CHANGED
@@ -15,8 +15,9 @@ it does mean that the clone operation must be applied with great care.
|
|
15
15
|
|
16
16
|
Unlike the standard clone method, the full\_clone method does not throw an
|
17
17
|
exception when it sees un-clonable value objects like 42 or true. These values
|
18
|
-
simply return themselves. This is correct because those types of objects
|
19
|
-
not
|
18
|
+
simply return themselves. This is deemed correct because those types of objects
|
19
|
+
are immutable and do not need to be duped. Instead of raising an exception, the
|
20
|
+
code returns the immutable object instead.
|
20
21
|
|
21
22
|
Another issue that this gem deals with is that of data with looping reference
|
22
23
|
chains. To handle this, the code tracks object ID values and does not re-clone
|
data/full_clone.gemspec
CHANGED
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency 'minitest', "~> 5.7"
|
23
23
|
spec.add_development_dependency 'minitest_visible', "~> 0.1"
|
24
|
-
|
24
|
+
spec.add_development_dependency 'reek', "~> 5.0.2"
|
25
25
|
end
|
data/lib/full_clone/array.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# Add full_clone support to all arrays.
|
1
4
|
class Array
|
2
5
|
|
3
|
-
#
|
4
|
-
def
|
5
|
-
|
6
|
-
|
6
|
+
# Do a full_clone with no exclusions
|
7
|
+
def full_clone_no_exclusions(progress)
|
8
|
+
each_index do |name|
|
9
|
+
value = self[name]
|
10
|
+
value = progress[value.object_id] || value.full_clone(progress)
|
11
|
+
self[name] = value
|
12
|
+
end
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
15
|
+
# Do a full_clone with exclusions
|
16
|
+
def full_clone_with_exclusions(progress, exclude)
|
17
|
+
each_index do |name|
|
18
|
+
unless exclude.include?(name)
|
19
|
+
value = self[name]
|
11
20
|
value = progress[value.object_id] || value.full_clone(progress)
|
12
|
-
|
13
|
-
end
|
14
|
-
else
|
15
|
-
each_index do |name|
|
16
|
-
unless exclude.include?(name)
|
17
|
-
value = result[name]
|
18
|
-
value = progress[value.object_id] || value.full_clone(progress)
|
19
|
-
result[name] = value
|
20
|
-
end
|
21
|
+
self[name] = value
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
|
-
result
|
25
24
|
end
|
26
25
|
|
27
26
|
end
|
data/lib/full_clone/hash.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# Add full_clone support to all hashes.
|
1
4
|
class Hash
|
2
5
|
|
3
|
-
#
|
4
|
-
def
|
5
|
-
|
6
|
-
|
6
|
+
# Do a full_clone with no exclusions
|
7
|
+
def full_clone_no_exclusions(progress)
|
8
|
+
each_key do |name|
|
9
|
+
value = self[name]
|
10
|
+
value = progress[value.object_id] || value.full_clone(progress)
|
11
|
+
self[name] = value
|
12
|
+
end
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
15
|
+
# Do a full_clone with exclusions
|
16
|
+
def full_clone_with_exclusions(progress, exclude)
|
17
|
+
each_key do |name|
|
18
|
+
unless exclude.include?(name)
|
19
|
+
value = self[name]
|
11
20
|
value = progress[value.object_id] || value.full_clone(progress)
|
12
|
-
|
13
|
-
end
|
14
|
-
else
|
15
|
-
each_key do |name|
|
16
|
-
unless exclude.include?(name)
|
17
|
-
value = result[name]
|
18
|
-
value = progress[value.object_id] || value.full_clone(progress)
|
19
|
-
result[name] = value
|
20
|
-
end
|
21
|
+
self[name] = value
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
|
-
result
|
25
24
|
end
|
26
25
|
|
27
26
|
end
|
data/lib/full_clone/object.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# Add full_clone support to all objects.
|
1
4
|
class Object
|
2
5
|
|
3
6
|
#By default, no instance variables are excluded.
|
@@ -5,28 +8,38 @@ class Object
|
|
5
8
|
[]
|
6
9
|
end
|
7
10
|
|
8
|
-
#The
|
11
|
+
#The common part of the full_clone method.
|
9
12
|
def full_clone(progress={})
|
10
13
|
progress[object_id] = result = clone
|
11
14
|
exclude = full_clone_exclude
|
12
15
|
|
13
16
|
if exclude.empty?
|
14
|
-
|
15
|
-
value = result.instance_variable_get(name)
|
16
|
-
value = progress[value.object_id] || value.full_clone(progress)
|
17
|
-
result.instance_variable_set(name, value)
|
18
|
-
end
|
17
|
+
result.full_clone_no_exclusions(progress)
|
19
18
|
else
|
20
|
-
|
21
|
-
unless exclude.include?(name)
|
22
|
-
value = result.instance_variable_get(name)
|
23
|
-
value = progress[value.object_id] || value.full_clone(progress)
|
24
|
-
result.instance_variable_set(name, value)
|
25
|
-
end
|
26
|
-
end
|
19
|
+
result.full_clone_with_exclusions(progress, exclude)
|
27
20
|
end
|
28
21
|
|
29
22
|
result
|
30
23
|
end
|
31
24
|
|
25
|
+
# Do a full_clone with no exclusions
|
26
|
+
def full_clone_no_exclusions(progress)
|
27
|
+
instance_variables.each do |name|
|
28
|
+
value = instance_variable_get(name)
|
29
|
+
value = progress[value.object_id] || value.full_clone(progress)
|
30
|
+
instance_variable_set(name, value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Do a full_clone with exclusions
|
35
|
+
def full_clone_with_exclusions(progress, exclude)
|
36
|
+
instance_variables.each do |name|
|
37
|
+
unless exclude.include?(name)
|
38
|
+
value = instance_variable_get(name)
|
39
|
+
value = progress[value.object_id] || value.full_clone(progress)
|
40
|
+
instance_variable_set(name, value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
32
45
|
end
|
data/lib/full_clone/struct.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# Add full_clone support to the struct class.
|
1
4
|
class Struct
|
2
5
|
|
3
|
-
#
|
4
|
-
def
|
5
|
-
|
6
|
-
|
6
|
+
# Do a full_clone with no exclusions
|
7
|
+
def full_clone_no_exclusions(progress)
|
8
|
+
members.each do |name|
|
9
|
+
value = self[name]
|
10
|
+
value = progress[value.object_id] || value.full_clone(progress)
|
11
|
+
self[name] = value
|
12
|
+
end
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
15
|
+
# Do a full_clone with exclusions
|
16
|
+
def full_clone_with_exclusions(progress, exclude)
|
17
|
+
members.each do |name|
|
18
|
+
unless exclude.include?(name)
|
19
|
+
value = self[name]
|
11
20
|
value = progress[value.object_id] || value.full_clone(progress)
|
12
|
-
|
13
|
-
end
|
14
|
-
else
|
15
|
-
members.each do |name|
|
16
|
-
unless exclude.include?(name)
|
17
|
-
value = result[name]
|
18
|
-
value = progress[value.object_id] || value.full_clone(progress)
|
19
|
-
result[name] = value
|
20
|
-
end
|
21
|
+
self[name] = value
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
|
-
result
|
25
24
|
end
|
26
25
|
|
27
26
|
end
|
data/lib/full_clone/use_clone.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
# A mixin for cloning use Ruby clone.
|
3
4
|
module FullCloneClone
|
4
5
|
def full_clone(_progress=nil)
|
5
6
|
clone
|
6
7
|
end
|
7
8
|
end
|
8
9
|
|
10
|
+
# String full clone support.
|
9
11
|
class String
|
10
12
|
include FullCloneClone
|
11
13
|
end
|
12
14
|
|
15
|
+
# Enumerator full clone support.
|
13
16
|
class Enumerator
|
14
17
|
include FullCloneClone
|
15
18
|
end
|
16
19
|
|
20
|
+
# Matchdata full clone support.
|
17
21
|
class MatchData
|
18
22
|
include FullCloneClone
|
19
23
|
end
|
data/lib/full_clone/use_self.rb
CHANGED
@@ -1,36 +1,43 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
# A mixin for cloning as self.
|
3
4
|
module FullCloneSelf
|
4
5
|
def full_clone(_progress=nil)
|
5
6
|
self
|
6
7
|
end
|
7
8
|
end
|
8
9
|
|
10
|
+
# Numeric supports full clone.
|
9
11
|
class Numeric
|
10
12
|
include FullCloneSelf
|
11
13
|
end
|
12
14
|
|
15
|
+
# NilClass supports full clone.
|
13
16
|
class NilClass
|
14
17
|
include FullCloneSelf
|
15
18
|
end
|
16
19
|
|
20
|
+
# TrueClass supports full clone.
|
17
21
|
class TrueClass
|
18
22
|
include FullCloneSelf
|
19
23
|
end
|
20
24
|
|
25
|
+
# FalseClass supports full clone.
|
21
26
|
class FalseClass
|
22
27
|
include FullCloneSelf
|
23
28
|
end
|
24
29
|
|
30
|
+
# Symbols support full clone.
|
25
31
|
class Symbol
|
26
32
|
include FullCloneSelf
|
27
33
|
end
|
28
34
|
|
35
|
+
# Regular expressions support full clone.
|
29
36
|
class Regexp
|
30
37
|
include FullCloneSelf
|
31
38
|
end
|
32
39
|
|
40
|
+
# Threads support full clone.
|
33
41
|
class Thread
|
34
42
|
include FullCloneSelf
|
35
43
|
end
|
36
|
-
|
data/lib/full_clone/version.rb
CHANGED
data/rakefile.rb
CHANGED
@@ -12,6 +12,11 @@ Rake::TestTask.new do |t|
|
|
12
12
|
t.verbose = false
|
13
13
|
end
|
14
14
|
|
15
|
+
desc "Run a scan for smelly code!"
|
16
|
+
task :reek do |t|
|
17
|
+
`reek --no-color lib > reek.txt`
|
18
|
+
end
|
19
|
+
|
15
20
|
desc "Run an IRB Session with full_clone loaded."
|
16
21
|
task :console do
|
17
22
|
system "ruby irbt.rb local"
|
data/reek.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0 total warnings
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: full_clone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: reek
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.0.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.0.2
|
69
83
|
description: A (safe/no exceptions) clone variant that performs a deep, recursive
|
70
84
|
copy.
|
71
85
|
email:
|
@@ -90,6 +104,7 @@ files:
|
|
90
104
|
- lib/full_clone/use_self.rb
|
91
105
|
- lib/full_clone/version.rb
|
92
106
|
- rakefile.rb
|
107
|
+
- reek.txt
|
93
108
|
- test/array_tests.rb
|
94
109
|
- test/deep_clone_tests.rb
|
95
110
|
- test/hash_tests.rb
|