full_dup 0.0.6 → 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: 20cf85cb4234f06a7460867e7ea8106d39354c23
4
- data.tar.gz: d6a798fe6cd7b325372d97b70b1502229f30fb09
3
+ metadata.gz: 86a384fd1d302d5e4aa4d0c559f7e54eef928dd2
4
+ data.tar.gz: 9323bcec6d5768a83462ead3fb90bc41274dee70
5
5
  SHA512:
6
- metadata.gz: 1dfd98c630f82771af60cc0edc6db998258e1e6dcdbc39062a8129194244c34e725df68bfaa12b63a5feb1d8d10fd5e16c0b707902e1ed7a1de716d697ccb344
7
- data.tar.gz: e47dcb7ba1044b94894e45c2241722dfee313b5b51ae93e32a1865945b6fa3d1221425e14a39704dd4402d383d392683095337df49557fca9225aac55611955e
6
+ metadata.gz: e0d14dfe054b64f3c6ab38cacb3d3fb5a81f8a32e6e633b3c50a7adf43cb27b6d5dcf9eb37e12eaf8868591c301af4eae80cc5b8ad527a43e0a357b3f5aefb71
7
+ data.tar.gz: 7ba748574f0bda5729bb178a318be629687b1f10ae673d92769b94eed6253fb74d43ea52203208c0845e7acaef6ddae1c58b5de23e76fef71a6d9b04d3a34189
@@ -21,4 +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
+ spec.add_development_dependency 'reek', "~> 5.0.2"
24
25
  end
@@ -1,29 +1,26 @@
1
1
  # coding: utf-8
2
2
 
3
+ # Add full_dup support to the array class.
3
4
  class Array
4
5
 
5
- #The full_dup method for arrays.
6
- def full_dup(progress={})
7
- progress[object_id] = result = dup
8
- exclude = full_dup_exclude
6
+ # Do a full_dup with no exclusions
7
+ def full_dup_no_exclusions(progress)
8
+ each_index do |name|
9
+ value = self[name]
10
+ value = progress[value.object_id] || value.full_dup(progress)
11
+ self[name] = value
12
+ end
13
+ end
9
14
 
10
- if exclude.empty?
11
- each_index do |name|
12
- value = result[name]
15
+ # Do a full_dup with exclusions
16
+ def full_dup_with_exclusions(progress, exclude)
17
+ each_index do |name|
18
+ unless exclude.include?(name)
19
+ value = self[name]
13
20
  value = progress[value.object_id] || value.full_dup(progress)
14
- result[name] = value
15
- end
16
- else
17
- each_index do |name|
18
- unless exclude.include?(name)
19
- value = result[name]
20
- value = progress[value.object_id] || value.full_dup(progress)
21
- result[name] = value
22
- end
21
+ self[name] = value
23
22
  end
24
23
  end
25
-
26
- result
27
24
  end
28
25
 
29
26
  end
@@ -1,29 +1,26 @@
1
- # coding: utf-8
2
-
3
- class Hash
4
-
5
- #The full_dup method for hashes.
6
- def full_dup(progress={})
7
- progress[object_id] = result = dup
8
- exclude = full_dup_exclude
9
-
10
- if exclude.empty?
11
- each_key do |name|
12
- value = result[name]
13
- value = progress[value.object_id] || value.full_dup(progress)
14
- result[name] = value
15
- end
16
- else
17
- each_key do |name|
18
- unless exclude.include?(name)
19
- value = result[name]
20
- value = progress[value.object_id] || value.full_dup(progress)
21
- result[name] = value
22
- end
23
- end
24
- end
25
-
26
- result
27
- end
28
-
29
- end
1
+ # coding: utf-8
2
+
3
+ # Add full_dup support to the hash class.
4
+ class Hash
5
+
6
+ # Do a full_dup with no exclusions
7
+ def full_dup_no_exclusions(progress)
8
+ each_key do |name|
9
+ value = self[name]
10
+ value = progress[value.object_id] || value.full_dup(progress)
11
+ self[name] = value
12
+ end
13
+ end
14
+
15
+ # Do a full_dup with exclusions
16
+ def full_dup_with_exclusions(progress, exclude)
17
+ each_key do |name|
18
+ unless exclude.include?(name)
19
+ value = self[name]
20
+ value = progress[value.object_id] || value.full_dup(progress)
21
+ self[name] = value
22
+ end
23
+ end
24
+ end
25
+
26
+ end
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
+ # Add full_dup support to the object class.
3
4
  class Object
4
5
 
5
6
  #By default, no instance variables are excluded.
@@ -7,28 +8,38 @@ class Object
7
8
  []
8
9
  end
9
10
 
10
- #The full_dup method for most objects.
11
+ #The common part of the full_dup.
11
12
  def full_dup(progress={})
12
13
  progress[object_id] = result = dup
13
14
  exclude = full_dup_exclude
14
15
 
15
16
  if exclude.empty?
16
- instance_variables.each do |name|
17
- value = result.instance_variable_get(name)
18
- value = progress[value.object_id] || value.full_dup(progress)
19
- result.instance_variable_set(name, value)
20
- end
17
+ result.full_dup_no_exclusions(progress)
21
18
  else
22
- instance_variables.each do |name|
23
- unless exclude.include?(name)
24
- value = result.instance_variable_get(name)
25
- value = progress[value.object_id] || value.full_dup(progress)
26
- result.instance_variable_set(name, value)
27
- end
28
- end
19
+ result.full_dup_with_exclusions(progress, exclude)
29
20
  end
30
21
 
31
22
  result
32
23
  end
33
24
 
25
+ # Do a full_dup with no exclusions
26
+ def full_dup_no_exclusions(progress)
27
+ instance_variables.each do |name|
28
+ value = instance_variable_get(name)
29
+ value = progress[value.object_id] || value.full_dup(progress)
30
+ instance_variable_set(name, value)
31
+ end
32
+ end
33
+
34
+ # Do a full_dup with exclusions
35
+ def full_dup_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_dup(progress)
40
+ instance_variable_set(name, value)
41
+ end
42
+ end
43
+ end
44
+
34
45
  end
@@ -1,29 +1,26 @@
1
1
  # coding: utf-8
2
2
 
3
+ # Add full_dup support to the struct class.
3
4
  class Struct
4
5
 
5
- #The full_dup method for structs.
6
- def full_dup(progress={})
7
- progress[object_id] = result = dup
8
- exclude = full_dup_exclude
6
+ # Do a full_dup with no exclusions
7
+ def full_dup_no_exclusions(progress)
8
+ members.each do |name|
9
+ value = self[name]
10
+ value = progress[value.object_id] || value.full_dup(progress)
11
+ self[name] = value
12
+ end
13
+ end
9
14
 
10
- if exclude.empty?
11
- members.each do |name|
12
- value = result[name]
15
+ # Do a full_dup with exclusions
16
+ def full_dup_with_exclusions(progress, exclude)
17
+ members.each do |name|
18
+ unless exclude.include?(name)
19
+ value = self[name]
13
20
  value = progress[value.object_id] || value.full_dup(progress)
14
- result[name] = value
15
- end
16
- else
17
- members.each do |name|
18
- unless exclude.include?(name)
19
- value = result[name]
20
- value = progress[value.object_id] || value.full_dup(progress)
21
- result[name] = value
22
- end
21
+ self[name] = value
23
22
  end
24
23
  end
25
-
26
- result
27
24
  end
28
25
 
29
26
  end
@@ -1,19 +1,23 @@
1
1
  # coding: utf-8
2
2
 
3
+ # The mixin for classes where dup is just simple dup.
3
4
  module FullDupDup
4
5
  def full_dup(_progress=nil)
5
6
  dup
6
7
  end
7
8
  end
8
9
 
10
+ # Strings answer dup.
9
11
  class String
10
12
  include FullDupDup
11
13
  end
12
14
 
15
+ # Enumerators answer dup.
13
16
  class Enumerator
14
17
  include FullDupDup
15
18
  end
16
19
 
20
+ # MatchData answer dup.
17
21
  class MatchData
18
22
  include FullDupDup
19
23
  end
@@ -1,35 +1,43 @@
1
1
  # coding: utf-8
2
2
 
3
+ # A mixin for classes where the dup is the object itself.
3
4
  module FullDupSelf
4
5
  def full_dup(_progress=nil)
5
6
  self
6
7
  end
7
8
  end
8
9
 
10
+ # Numerics answer self.
9
11
  class Numeric
10
12
  include FullDupSelf
11
13
  end
12
14
 
15
+ # NilClass objects (nil) answer self.
13
16
  class NilClass
14
17
  include FullDupSelf
15
18
  end
16
19
 
20
+ # TrueClass objects (true) answer self.
17
21
  class TrueClass
18
22
  include FullDupSelf
19
23
  end
20
24
 
25
+ # FalseClass objects (false) answer self.
21
26
  class FalseClass
22
27
  include FullDupSelf
23
28
  end
24
29
 
30
+ # Symbols answer self.
25
31
  class Symbol
26
32
  include FullDupSelf
27
33
  end
28
34
 
35
+ # Regular expressions answer self.
29
36
  class Regexp
30
37
  include FullDupSelf
31
38
  end
32
39
 
40
+ # Threads answer self.
33
41
  class Thread
34
42
  include FullDupSelf
35
43
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module FullDup
4
- VERSION = "0.0.6"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -14,6 +14,11 @@ Rake::TestTask.new do |t|
14
14
  t.warning = true
15
15
  end
16
16
 
17
+ desc "Run a scan for smelly code!"
18
+ task :reek do |t|
19
+ `reek --no-color lib > reek.txt`
20
+ end
21
+
17
22
  desc "Fire up an IRB session with full_dup preloaded."
18
23
  task :console do
19
24
  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_dup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
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-05 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) dup variant that performs a deep, recursive copy.
70
84
  email:
71
85
  - peter.c.camilleri@gmail.com
@@ -89,6 +103,7 @@ files:
89
103
  - lib/full_dup/use_self.rb
90
104
  - lib/full_dup/version.rb
91
105
  - rakefile.rb
106
+ - reek.txt
92
107
  homepage: https://github.com/PeterCamilleri/full_dup
93
108
  licenses:
94
109
  - MIT