full_clone 0.0.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97944e660887dfe2a84d165cb26d2dc6e97b8b40
4
- data.tar.gz: 9e03f91b6587a868fec985a1955c8d3697af0015
3
+ metadata.gz: 8385b340fff44a74cd9d7331d4736d3cfcb6ef3e
4
+ data.tar.gz: 83549c5119a63deafacb4b8f4c22cff46d8569ed
5
5
  SHA512:
6
- metadata.gz: 8bbbad200de9137bdb3ab810fdddbba2dd7b0e0eb993d7aaef6409ab1817e8f6efcab2b8eeb17d2e102a9cabab0da1b175209452a469fd2cf54da103ff081691
7
- data.tar.gz: 9bada8380789f7227a6a809a1bf9393fb8ba1e035e9446adb1c6df7b90eaf3ef9474dfaeac3ec267035f965f7e95d52862c1028d25abc34879b7971bfa3cf9e3
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 do
19
- not _need_ to be cloned. Instead of having a fit, the code just works!
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
@@ -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
@@ -1,27 +1,26 @@
1
+ # coding: utf-8
2
+
3
+ # Add full_clone support to all arrays.
1
4
  class Array
2
5
 
3
- #The full_clone method for arrays.
4
- def full_clone(progress={})
5
- progress[object_id] = result = clone
6
- exclude = full_clone_exclude
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
- if exclude.empty?
9
- each_index do |name|
10
- value = result[name]
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
- result[name] = value
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
@@ -1,27 +1,26 @@
1
+ # coding: utf-8
2
+
3
+ # Add full_clone support to all hashes.
1
4
  class Hash
2
5
 
3
- #The full_clone method for structs.
4
- def full_clone(progress={})
5
- progress[object_id] = result = clone
6
- exclude = full_clone_exclude
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
- if exclude.empty?
9
- each_key do |name|
10
- value = result[name]
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
- result[name] = value
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
@@ -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 full_clone method for most objects.
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
- instance_variables.each do |name|
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
- instance_variables.each do |name|
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
@@ -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
- #The full_clone method for structs.
4
- def full_clone(progress={})
5
- progress[object_id] = result = clone
6
- exclude = full_clone_exclude
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
- if exclude.empty?
9
- members.each do |name|
10
- value = result[name]
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
- result[name] = value
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
@@ -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
@@ -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
-
@@ -1,3 +1,3 @@
1
1
  module FullClone
2
- VERSION = "0.0.10"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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"
@@ -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.10
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-08-06 00:00:00.000000000 Z
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