safe_dup 0.0.7 → 1.0.3

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
- SHA1:
3
- metadata.gz: fecb2bb437fe993c25f9c37279332468bbb2ebf7
4
- data.tar.gz: 6ca25ab7b90a06b109d50d9e6462a6125805ef16
2
+ SHA256:
3
+ metadata.gz: a6e96cd875e95c7d23ba1bf54f9c2e51745b4c40f9efb04dd7b52fc06ee17360
4
+ data.tar.gz: b8370214990b0cab71ed22fe5ff727ddcc3f5f5da1a8f8e903c5bac748857703
5
5
  SHA512:
6
- metadata.gz: 38734e288e3089aa4721d18dc8e1eba0c6f33950e527663936a58b3f1c4c40960e6c6e33bea18af37f3e384457e608c4fa27af78cbf9759b16ad5be537b72867
7
- data.tar.gz: af278ee7942676d7e691f66cf466dcb81e29a44a2bd1b3962e0a224698411d1a3c1967bb0d1ee380e91a94838005911753b3936db39939c4be140506eb2509e1
6
+ metadata.gz: b2f65ef3e7d791db28a0068e567349fd36139a51d2a28f9fd2dedd2444f4460cabaa040767fa26ec04c0c568d4778fecf16d5026d44d004461a96012d0720b92
7
+ data.tar.gz: 664cfdd4acd346bbe8c8cbf259edbb6402a7061101c4b967c81689506b84e29a09387758f6125bdf454f2cfaf378b75ce941bb5042cb3c60e804085ba10c1c61
data/README.md CHANGED
@@ -7,8 +7,9 @@ it does mean that the dup operation must be applied with great care.
7
7
 
8
8
  Unlike the standard dup method, the safe\_dup method does not throw an
9
9
  exception when sent to un-clonable value objects like 42 or true. These values
10
- simply return themselves. This is correct because those types of objects do
11
- not _need_ to be dupd. Instead of having a fit, the code just works!
10
+ simply return themselves. This is deemed correct because those types of objects
11
+ are immutable and do not need to be duped. Instead of raising an exception,
12
+ the code returns the immutable object instead.
12
13
 
13
14
  On a note about performance, this gem does not just rescue the exceptions
14
15
  normally generated by dup, it prevents them from occurring and wasting time
@@ -171,6 +172,21 @@ end
171
172
  Dup with the safe dup method: 450557.6 i/s
172
173
  Dup with standard dup method: 39436.6 i/s - 11.42x slower
173
174
 
175
+ #### Results: ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
176
+ Warming up --------------------------------------
177
+ Dup with standard clone method
178
+ 5.866k i/100ms
179
+ Dup with the safe clone method
180
+ 23.721k i/100ms
181
+ Calculating -------------------------------------
182
+ Dup with standard clone method
183
+ 70.492k (± 0.4%) i/s - 357.826k in 5.076221s
184
+ Dup with the safe clone method
185
+ 523.478k (± 1.1%) i/s - 2.633M in 5.030544s
186
+
187
+ Comparison:
188
+ Dup with the safe clone method: 523477.8 i/s
189
+ Dup with standard clone method: 70491.9 i/s - 7.43x slower
174
190
 
175
191
 
176
192
  Overall: Shorter code _and_ faster. Winner, winner, chicken dinner!
@@ -190,3 +206,13 @@ Overall: Shorter code _and_ faster. Winner, winner, chicken dinner!
190
206
  Go to the GitHub repository and raise an issue calling attention to some
191
207
  aspect that could use some TLC or a suggestion or an idea.
192
208
 
209
+ ## License
210
+
211
+ The gem is available as open source under the terms of the
212
+ [MIT License](./LICENSE.txt).
213
+
214
+ ## Code of Conduct
215
+
216
+ Everyone interacting in the fully_freeze project’s codebases, issue trackers,
217
+ chat rooms and mailing lists is expected to follow the
218
+ [code of conduct](./CODE_OF_CONDUCT.md).
data/lib/safe_dup.rb CHANGED
@@ -1,21 +1,53 @@
1
+ # coding: utf-8
1
2
 
2
3
  require_relative "safe_dup/version"
3
4
 
5
+ # Now you too can dup objects without fear of annoying exceptions!
4
6
  class Object
5
- #By default, reference types use the clone method.
6
- def safe_dup; self.dup; end
7
+ #By default, reference types use the dup method.
8
+ def safe_dup
9
+ dup
10
+ end
7
11
  end
8
12
 
9
- #For value types, just return self!
13
+ # For value types, just return self!
10
14
  module SafeDup
11
- def safe_dup; self; end
15
+ def safe_dup
16
+ self
17
+ end
12
18
  end
13
19
 
14
- #Update the Ruby value types.
15
- class Numeric; include SafeDup; end
16
- class NilClass; include SafeDup; end
17
- class TrueClass; include SafeDup; end
18
- class FalseClass; include SafeDup; end
19
- class Symbol; include SafeDup; end
20
- class Regexp; include SafeDup; end
20
+ # Numeric can now safe dup.
21
+ class Numeric
22
+ include SafeDup
23
+ end
24
+
25
+ # NilClass can now safe dup.
26
+ class NilClass
27
+ include SafeDup
28
+ end
29
+
30
+ # TrueClass can now safe dup.
31
+ class TrueClass
32
+ include SafeDup
33
+ end
34
+
35
+ # FalseClass can now safe dup.
36
+ class FalseClass
37
+ include SafeDup
38
+ end
39
+
40
+ # Symbols can now safe dup.
41
+ class Symbol
42
+ include SafeDup
43
+ end
21
44
 
45
+ # Regular expressions can now safe dup.
46
+ class Regexp
47
+ include SafeDup
48
+ end
49
+
50
+ # Threads can now safe dup.
51
+ class Thread
52
+ include SafeDup
53
+ end
@@ -1,3 +1,3 @@
1
1
  module SafeDup
2
- VERSION = "0.0.7"
2
+ VERSION = "1.0.3"
3
3
  end
data/rakefile.rb CHANGED
@@ -8,6 +8,11 @@ Rake::TestTask.new do |t|
8
8
  t.verbose = false
9
9
  end
10
10
 
11
+ desc "Run a scan for smelly code!"
12
+ task :reek do |t|
13
+ `reek --no-color lib > reek.txt`
14
+ end
15
+
11
16
  desc "Fire up an IRB session with safe_dup preloaded."
12
17
  task :console do
13
18
  system "ruby irbt.rb local"
data/reek.txt ADDED
@@ -0,0 +1 @@
1
+ 0 total warnings
data/safe_dup.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "rake", "~> 12.0"
22
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake", ">= 12.3.3"
22
+ spec.add_development_dependency "bundler", ">= 2.1.0"
23
23
  spec.add_development_dependency 'minitest', "~> 5.7"
24
- spec.add_development_dependency 'minitest_visible', "~> 0.1"
24
+ spec.add_development_dependency 'reek', "~> 5.0.2"
25
25
  end
@@ -3,14 +3,10 @@
3
3
  require_relative '../lib/safe_dup'
4
4
  gem 'minitest'
5
5
  require 'minitest/autorun'
6
- require 'minitest_visible'
7
6
 
8
7
  #Test the monkey patches applied to the Object class.
9
8
  class SafeDupTester < Minitest::Test
10
9
 
11
- #Track mini-test progress.
12
- include MinitestVisible
13
-
14
10
  def test_for_safe_value_cloning
15
11
  assert_equal((6).safe_dup, 6)
16
12
  assert_equal((6).safe_dup.object_id, (6).object_id)
@@ -24,7 +20,7 @@ class SafeDupTester < Minitest::Test
24
20
  assert_equal((false).safe_dup, false)
25
21
  assert_equal((false).safe_dup.object_id, (false).object_id)
26
22
 
27
- assert_equal((nil).safe_dup, nil)
23
+ assert_nil((nil).safe_dup)
28
24
  assert_equal((nil).safe_dup.object_id, (nil).object_id)
29
25
 
30
26
  rex = /ABC/
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_dup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '12.0'
19
+ version: 12.3.3
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '12.0'
26
+ version: 12.3.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: 2.1.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.7'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest_visible
56
+ name: reek
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.1'
61
+ version: 5.0.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.1'
68
+ version: 5.0.2
69
69
  description: A safer version of the dup method that avoids unnecessary exceptions.
70
70
  email:
71
71
  - peter.c.camilleri@gmail.com
@@ -83,6 +83,7 @@ files:
83
83
  - lib/safe_dup.rb
84
84
  - lib/safe_dup/version.rb
85
85
  - rakefile.rb
86
+ - reek.txt
86
87
  - safe_dup.gemspec
87
88
  - test/safe_dup_tests.rb
88
89
  homepage: https://github.com/PeterCamilleri/safe_dup
@@ -104,11 +105,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  - !ruby/object:Gem::Version
105
106
  version: '0'
106
107
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.2.3
108
+ rubygems_version: 3.2.17
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: A safer version of the dup method.
112
112
  test_files:
113
113
  - test/safe_dup_tests.rb
114
- has_rdoc: