init_copy 0.2.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1620d2aa498e981be870fd3e0d671595b0407e557b54e40cf7e32b38b95158a8
4
- data.tar.gz: 1b08062be47d208e59ed5a70e548f726d55936ccc000a84bbda5b2ed47119360
3
+ metadata.gz: ae95968b85aaaf5b99b3f6a6baa656c507c929c3b131a4033dc70aa53da771a1
4
+ data.tar.gz: 0ab5144c33d40065472d34d7f518d1d6b22d62f84673e5535b505c9897208a53
5
5
  SHA512:
6
- metadata.gz: 17b1bc267564f9f49c5b699581f522690bc13a63addbab7708bbb6af227970f3701c0f259d00d0d42b4c898e5b349324672b416395d5d0d34be151cf48994db0
7
- data.tar.gz: e2973b90f3bd28a061904a1db08435b2f2a5af11c2a7bc4d14ce1a40bfbc7837099b0c8c786ea39b064714b041d87994420890ff6f6ae30afb621dac6f31d89b
6
+ metadata.gz: ad48b02c42b4e53b2cd39c7e79cfd8eb1cc7d9dee97c48109d8dc6e5177f382ca31b3ff82610b35951429212957e2fa695c00064e1551527e9d22a4b8c28c05f
7
+ data.tar.gz: e9c728cdfc1ae494f18ff570f02787a4e6cabc264255eaf4b7d943410ce381b99dffcc05c3745f6b08af3fdd667e8229bb244eae62689987f3e0b4ca75a462ef
data/.rdoc_options CHANGED
@@ -11,6 +11,7 @@ embed_mixins: true
11
11
  force_update: true
12
12
  hyperlink_all: true
13
13
  line_numbers: true
14
+ markup: markdown
14
15
  show_hash: true
15
16
  skip_tests: true
16
17
 
data/Gemfile CHANGED
@@ -5,12 +5,13 @@ source 'https://rubygems.org'
5
5
 
6
6
  gemspec
7
7
 
8
- group :development,:test do
9
- gem 'bundler' ,'~> 2.6'
10
- gem 'rake' ,'~> 13.3'
11
- gem 'rdoc' ,'~> 6.14'
8
+ group(:development,:test) do
9
+ gem 'bundler','~> 2.6'
10
+ gem 'rake','~> 13.3.0'
11
+
12
+ gem 'rdoc','~> 6.14.0' # Doc.
12
13
  end
13
14
 
14
- group :test do
15
- gem 'minitest' ,'~> 5.25'
15
+ group(:test) do
16
+ gem 'minitest','~> 5.25.0' # Tests.
16
17
  end
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/init_copy.svg)](https://badge.fury.io/rb/init_copy)
4
4
  [![CI Status](https://github.com/esotericpig/init_copy/actions/workflows/ci.yml/badge.svg)](https://github.com/esotericpig/init_copy/actions/workflows/ci.yml)
5
-
6
5
  [![Source Code](https://img.shields.io/badge/source-github-%23211F1F.svg)](https://github.com/esotericpig/init_copy)
7
6
  [![Changelog](https://img.shields.io/badge/changelog-md-%23A0522D.svg)](CHANGELOG.md)
8
7
  [![License](https://img.shields.io/github/license/esotericpig/init_copy.svg)](LICENSE.txt)
@@ -18,6 +17,7 @@ module SecretExt
18
17
  end
19
18
  end
20
19
 
20
+ # Init vars.
21
21
  bob = 'Bob'
22
22
  bob.extend(SecretExt)
23
23
  bob.freeze
@@ -25,6 +25,7 @@ bob.freeze
25
25
  clone = bob.clone
26
26
  dup = bob.dup
27
27
 
28
+ # Check vars.
28
29
  puts clone.frozen? #=> true
29
30
  puts dup.frozen? #=> false
30
31
 
@@ -35,8 +36,9 @@ puts dup.secret #=> NoMethodError
35
36
  To solve this issue in the past, we had to define both `initialize_clone` & `initialize_dup` and maintain two copies of all our deep-copy code. That sucks. 😞
36
37
 
37
38
  🚀 Instead, *InitCopy* was created:
38
- 1. Install the gem `init_copy` ([RubyGems.org page](https://rubygems.org/gems/init_copy)).
39
- 2. Include `InitCopy` in your class/module.
39
+
40
+ 1. Install the gem `init_copy` ([on RubyGems.org](https://rubygems.org/gems/init_copy)).
41
+ 2. Include `InitCopy::Able` in your class/module.
40
42
  3. Override the `init_copy(original)` method.
41
43
  4. Use `ic_copy(var)`, instead of clone/dup.
42
44
 
@@ -46,14 +48,15 @@ Example usage:
46
48
  require 'init_copy'
47
49
 
48
50
  class JangoFett
49
- include InitCopy
51
+ include InitCopy::Able
50
52
 
51
- attr_reader :gear,:order66
53
+ attr_reader :gear,:bounties,:order66
52
54
 
53
55
  def initialize
54
56
  super
55
57
 
56
58
  @gear = ['blaster','jetpack']
59
+ @bounties = ['Padmé','Vosa']
57
60
 
58
61
  @order66 = Class.new do
59
62
  undef_method :clone
@@ -67,12 +70,15 @@ class JangoFett
67
70
  super
68
71
 
69
72
  @gear = ic_copy(@gear)
73
+ @bounties = ic_copy(@bounties)
74
+
70
75
  @order66 = ic_copy?(@order66) # Safe copy if no dup/clone.
71
76
  end
72
77
  end
73
78
 
79
+ # Init vars.
74
80
  jango = JangoFett.new
75
- jango.freeze
81
+ jango.bounties.freeze
76
82
 
77
83
  boba1 = jango.clone
78
84
  boba2 = jango.dup
@@ -80,13 +86,17 @@ boba2 = jango.dup
80
86
  jango.gear << 'vibroblade'
81
87
  boba1.gear << 'implant'
82
88
 
83
- puts jango.gear.inspect #=> ["blaster", "jetpack", "vibroblade"]
89
+ # Check vars.
90
+ puts jango.gear.inspect #=> ["blaster", "jetpack", "vibroblade"]
84
91
 
85
- puts boba1.gear.inspect #=> ["blaster", "jetpack", "implant"]
86
- puts boba2.gear.inspect #=> ["blaster", "jetpack"]
92
+ puts boba1.gear.inspect #=> ["blaster", "jetpack", "implant"]
93
+ puts boba2.gear.inspect #=> ["blaster", "jetpack"]
87
94
 
88
- puts boba1.frozen? #=> true (clone)
89
- puts boba2.frozen? #=> false (dup)
95
+ puts boba1.bounties.inspect #=> ["Padmé", "Vosa"]
96
+ puts boba2.bounties.inspect #=> ["Padmé", "Vosa"]
97
+
98
+ puts boba1.bounties.frozen? #=> true (clone)
99
+ puts boba2.bounties.frozen? #=> false (dup)
90
100
  ```
91
101
 
92
102
  ## // Contents
@@ -114,16 +124,15 @@ spec.add_dependency 'init_copy', '~> X.X'
114
124
  In your *Gemfile*:
115
125
 
116
126
  ```ruby
117
- # Pick one...
127
+ # Pick your poison...
118
128
  gem 'init_copy', '~> X.X'
119
-
120
129
  gem 'init_copy', git: 'https://github.com/esotericpig/init_copy.git', branch: 'main'
121
130
  ```
122
131
 
123
132
  From source:
124
133
 
125
134
  ```bash
126
- git clone 'https://github.com/esotericpig/init_copy.git'
135
+ git clone --depth 1 'https://github.com/esotericpig/init_copy.git'
127
136
  cd init_copy
128
137
  bundle install
129
138
  bundle exec rake install:local
data/Rakefile CHANGED
@@ -3,12 +3,12 @@
3
3
 
4
4
  require 'bundler/gem_tasks'
5
5
 
6
- require 'init_copy'
6
+ require 'init_copy/version'
7
7
  require 'rake/clean'
8
8
  require 'rake/testtask'
9
9
  require 'rdoc/task'
10
10
 
11
- CLEAN.exclude('.git/','.github/','.idea/','stock/')
11
+ CLEAN.exclude('{.git,.github,.idea,stock}/**/*')
12
12
  CLOBBER.include('doc/')
13
13
 
14
14
  task default: %i[test]
data/init_copy.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative 'lib/init_copy'
4
+ require_relative 'lib/init_copy/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'init_copy'
@@ -15,15 +15,14 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.metadata = {
17
17
  'rubygems_mfa_required' => 'true',
18
- 'homepage_uri' => 'https://github.com/esotericpig/init_copy',
18
+ 'homepage_uri' => spec.homepage,
19
19
  'source_code_uri' => 'https://github.com/esotericpig/init_copy',
20
20
  'bug_tracker_uri' => 'https://github.com/esotericpig/init_copy/issues',
21
21
  'changelog_uri' => 'https://github.com/esotericpig/init_copy/blob/main/CHANGELOG.md',
22
22
  }
23
23
 
24
- # Lowest version that isn't eol (end-of-life).
25
24
  # - https://www.ruby-lang.org/en/downloads/branches/
26
- spec.required_ruby_version = '>= 3.2'
25
+ spec.required_ruby_version = '>= 3.1'
27
26
  spec.require_paths = ['lib']
28
27
  spec.bindir = 'bin'
29
28
  spec.executables = []
@@ -31,6 +30,8 @@ Gem::Specification.new do |spec|
31
30
  spec.extra_rdoc_files = %w[LICENSE.txt README.md]
32
31
  spec.rdoc_options = [
33
32
  %w[--embed-mixins --hyperlink-all --line-numbers --show-hash],
33
+ '--encoding','UTF-8',
34
+ '--markup','markdown',
34
35
  '--main','README.md',
35
36
  '--title',"InitCopy v#{InitCopy::VERSION}",
36
37
  ].flatten
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ #--
5
+ # This file is part of InitCopy.
6
+ # Copyright (c) 2025 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: MIT
9
+ #++
10
+
11
+ module InitCopy
12
+ VERSION = '0.3.1'
13
+ end
data/lib/init_copy.rb CHANGED
@@ -8,11 +8,13 @@
8
8
  # SPDX-License-Identifier: MIT
9
9
  #++
10
10
 
11
+ require 'init_copy/version'
12
+
11
13
  # Example usage:
12
14
  # require 'init_copy'
13
15
  #
14
16
  # class JangoFett
15
- # include InitCopy
17
+ # include InitCopy::Able
16
18
  #
17
19
  # protected
18
20
  #
@@ -24,33 +26,11 @@
24
26
  # end
25
27
  # end
26
28
  module InitCopy
27
- VERSION = '0.2.0'
28
-
29
- def self.included(mod)
30
- super
31
-
32
- # NOTE: Can't use prepend(), else children's init_copy() won't call their parents', even with super().
33
- mod.include(Copyable)
34
- end
35
-
36
- def self.extended(mod)
37
- super
38
-
39
- mod.include(Copyable)
40
- end
41
-
42
- def self.prepended(mod)
43
- super
44
-
45
- # User specifically requested to prepend.
46
- mod.prepend(Copyable)
47
- end
48
-
49
- module Copyable
29
+ module Able
50
30
  def initialize_clone(orig)
51
31
  super
52
32
 
53
- # The instance variable name is long & obnoxious to reduce conflicts.
33
+ # The instance var name is long & obnoxious to reduce conflicts.
54
34
  @__init_copy_method_name = :clone
55
35
  init_copy(orig)
56
36
  end
@@ -12,196 +12,182 @@ require 'minitest/autorun'
12
12
 
13
13
  require 'init_copy'
14
14
 
15
- class InitCopyTest < Minitest::Test
16
- # def setup
17
- # end
15
+ describe InitCopy do
16
+ it 'has the version' do
17
+ _(InitCopy::VERSION).must_match(/\d+\.\d+\.\d+(-[0-9A-Za-z\-.]+)?(\+[0-9A-Za-z\-.]+)?/)
18
+ end
18
19
 
19
- def test_include
20
- %i[include extend prepend].each do |method|
21
- sut_class = Class.new
22
- sut_class.__send__(method,InitCopy)
20
+ def self.it_does_a_shallow_copy
21
+ it 'is not the same as the copies' do
22
+ _(@sut).wont_be_same_as(@sut_clone)
23
+ _(@sut).wont_be_same_as(@sut_dup)
24
+ end
23
25
 
24
- assert_includes(sut_class.included_modules,InitCopy::Copyable,
25
- "`#{method}` of InitCopy should include InitCopy::Copyable")
26
+ it 'has the correct copy method name' do
27
+ _(@sut.init_copy_method_name).must_be_nil
28
+ _(@sut_clone.init_copy_method_name).must_equal(:clone)
29
+ _(@sut_dup.init_copy_method_name).must_equal(:dup)
26
30
  end
27
31
  end
28
32
 
29
- def test_no_copy
30
- sut = TestBag.new
31
-
32
- refute_deep_copy(sut,sut.clone,:clone)
33
- refute_deep_copy(sut,sut.dup,:dup)
34
- end
33
+ def self.it_does_a_deep_copy(is_frozen: false)
34
+ it 'has the correct original' do
35
+ _(@sut.orig).must_be_nil
36
+ _(@sut_clone.orig).must_be_same_as(@sut)
37
+ _(@sut_dup.orig).must_be_same_as(@sut)
38
+ end
35
39
 
36
- def test_clone
37
- sut = TestBagWithCopy.new
40
+ it 'does a deep copy' do
41
+ _(@sut.nums).wont_be_same_as(@sut_clone.nums)
42
+ _(@sut.nums).wont_be_same_as(@sut_dup.nums)
38
43
 
39
- assert_deep_copy(sut,sut.clone,:clone)
40
- end
44
+ expected = [1,2,3]
41
45
 
42
- def test_dup
43
- sut = TestBagWithCopy.new
46
+ _(@sut.nums).must_equal(expected)
47
+ _(@sut_clone.nums).must_equal(expected)
48
+ _(@sut_dup.nums).must_equal(expected)
44
49
 
45
- assert_deep_copy(sut,sut.dup,:dup)
46
- end
50
+ if !is_frozen
51
+ @sut.nums << 4
52
+ @sut_clone.nums << 5
53
+ @sut_dup.nums << 6
47
54
 
48
- def test_correct_clone_and_dup_behavior
49
- sut_ext = Module.new do
50
- def bonus
51
- return 100
55
+ _(@sut.nums).must_equal([1,2,3,4])
56
+ _(@sut_clone.nums).must_equal([1,2,3,5])
57
+ _(@sut_dup.nums).must_equal([1,2,3,6])
52
58
  end
53
59
  end
54
-
55
- sut = TestBagWithCopy.new
56
- sut.extend(sut_ext)
57
-
58
- assert_deep_copy(sut,sut.clone,:clone)
59
- assert_deep_copy(sut,sut.dup,:dup)
60
-
61
- sut.nums.freeze
62
- sut_clone = sut.clone
63
- sut_dup = sut.dup
64
-
65
- assert_predicate(sut.nums,:frozen?,'SUT nums should be frozen')
66
- assert_respond_to(sut,:bonus,'SUT should have the bonus extension')
67
- assert_equal(100,sut.bonus)
68
-
69
- assert_predicate(sut_clone.nums,:frozen?,'clone should keep the nums as frozen')
70
- assert_respond_to(sut_clone,:bonus,'clone should keep the bonus extension')
71
- assert_equal(100,sut_clone.bonus)
72
-
73
- refute_predicate(sut_dup.nums,:frozen?,'dup should remove the internal frozen state of nums')
74
- refute_respond_to(sut_dup,:bonus,'dup should remove the bonus extension')
75
- assert_raises(NoMethodError) { sut_dup.bonus }
76
60
  end
77
61
 
78
- def test_safe_copy
79
- sut = TestBagWithSafeCopy.new
80
-
81
- assert_respond_to(sut.nums,:clone)
82
- assert_respond_to(sut.nums,:dup)
83
-
84
- assert_deep_copy(sut,sut.clone,:clone)
85
- assert_deep_copy(sut,sut.dup,:dup)
86
-
87
- class << sut.nums
88
- undef_method :clone
89
- undef_method :dup
62
+ describe 'without copy' do
63
+ before do
64
+ @sut = TestBag.new
65
+ @sut_clone = @sut.clone
66
+ @sut_dup = @sut.dup
90
67
  end
91
68
 
92
- refute_respond_to(sut.nums,:clone)
93
- refute_respond_to(sut.nums,:dup)
94
-
95
- refute_deep_copy(sut,sut.clone,:clone,is_safe_copy: true)
96
- refute_deep_copy(sut,sut.dup,:dup,is_safe_copy: true)
97
-
98
- # Make sure we didn't remove clone()/dup() for all arrays.
99
- assert_respond_to([1,2,3],:clone)
100
- assert_respond_to([1,2,3],:dup)
101
- end
102
-
103
- def test_child_copy
104
- sut_class = Class.new(TestBagWithCopy) do
105
- attr_reader :strs
106
-
107
- def initialize
108
- super
109
-
110
- @strs = %w[a b c]
111
- end
112
-
113
- def init_copy(*)
114
- super
69
+ it_does_a_shallow_copy
115
70
 
116
- @strs = ic_copy(@strs)
117
- end
71
+ it 'has no original' do
72
+ _(@sut.orig).must_be_nil
73
+ _(@sut_clone.orig).must_be_nil
74
+ _(@sut_dup.orig).must_be_nil
118
75
  end
119
76
 
120
- sut = sut_class.new
121
- sut_clone = sut.clone
122
- sut_dup = sut.dup
77
+ it 'does not do a deep copy' do
78
+ _(@sut.nums).must_be_same_as(@sut_clone.nums)
79
+ _(@sut.nums).must_be_same_as(@sut_dup.nums)
123
80
 
124
- assert_deep_copy(sut,sut_clone,:clone)
125
- assert_deep_copy(sut,sut_dup,:dup)
81
+ expected = [1,2,3]
126
82
 
127
- expected = %w[a b c]
83
+ _(@sut.nums).must_equal(expected)
84
+ _(@sut_clone.nums).must_equal(expected)
85
+ _(@sut_dup.nums).must_equal(expected)
128
86
 
129
- refute_same(sut.strs,sut_clone.strs)
130
- refute_same(sut.strs,sut_dup.strs)
131
- assert_equal(expected,sut.strs)
132
- assert_equal(expected,sut_clone.strs)
133
- assert_equal(expected,sut_dup.strs)
87
+ @sut.nums << 4
88
+ @sut_clone.nums << 5
89
+ @sut_dup.nums << 6
134
90
 
135
- sut.strs << 'd'
136
- sut_clone.strs << 'e'
137
- sut_dup.strs << 'f'
91
+ expected = [1,2,3,4,5,6]
138
92
 
139
- assert_equal(%w[a b c d],sut.strs)
140
- assert_equal(%w[a b c e],sut_clone.strs)
141
- assert_equal(%w[a b c f],sut_dup.strs)
93
+ _(@sut.nums).must_equal(expected)
94
+ _(@sut_clone.nums).must_equal(expected)
95
+ _(@sut_dup.nums).must_equal(expected)
96
+ end
142
97
  end
143
98
 
144
- def assert_deep_copy(sut,sut_copy,copy_method_name)
145
- refute_same(sut,sut_copy)
99
+ describe 'with copy' do
100
+ before do
101
+ @sut = TestBagWithCopy.new
102
+ @sut_clone = @sut.clone
103
+ @sut_dup = @sut.dup
104
+ end
146
105
 
147
- assert_nil(sut.init_copy_method_name)
148
- assert_equal(copy_method_name,sut_copy.init_copy_method_name)
106
+ it_does_a_shallow_copy
107
+ it_does_a_deep_copy
108
+ end
149
109
 
150
- assert_nil(sut.orig)
151
- assert_same(sut,sut_copy.orig)
110
+ describe 'with copy and internal state' do
111
+ before do
112
+ @sut = TestBagWithCopy.new
113
+
114
+ @sut.nums.extend(
115
+ Module.new do
116
+ def bonus
117
+ return 110
118
+ end
119
+ end
120
+ )
121
+ @sut.nums.freeze
122
+
123
+ @sut_clone = @sut.clone
124
+ @sut_dup = @sut.dup
125
+ end
152
126
 
153
- expected = [1,2,3]
127
+ it_does_a_shallow_copy
128
+ it_does_a_deep_copy(is_frozen: true)
154
129
 
155
- refute_same(sut.nums,sut_copy.nums)
156
- assert_equal(expected,sut.nums)
157
- assert_equal(expected,sut_copy.nums)
130
+ it 'has the correct bonus extension' do
131
+ _(@sut.nums).must_respond_to(:bonus,'SUT should have the nums bonus extension')
132
+ _(@sut.nums.bonus).must_equal(110)
158
133
 
159
- sut.nums << 4
160
- sut_copy.nums << 5
134
+ _(@sut_clone.nums).must_respond_to(:bonus,'clone should keep the nums bonus extension')
135
+ _(@sut_clone.nums.bonus).must_equal(110)
161
136
 
162
- assert_equal([1,2,3,4],sut.nums)
163
- assert_equal([1,2,3,5],sut_copy.nums)
137
+ _(@sut_dup.nums).wont_respond_to(:bonus,'dup should remove the nums bonus extension')
138
+ _ { @sut_dup.bonus }.must_raise(NoMethodError)
139
+ end
164
140
 
165
- # Reset.
166
- sut.nums.pop
167
- sut_copy.nums.pop
141
+ it 'has the correct frozen state' do
142
+ _(@sut.nums.frozen?).must_equal(true,'SUT should have the nums as frozen')
143
+ _(@sut_clone.nums.frozen?).must_equal(true,'clone should keep the nums as frozen')
144
+ _(@sut_dup.nums.frozen?).must_equal(false,'dup should remove the nums as frozen')
145
+ end
168
146
  end
169
147
 
170
- def refute_deep_copy(sut,sut_copy,copy_method_name,is_safe_copy: false)
171
- refute_same(sut,sut_copy)
172
-
173
- assert_nil(sut.init_copy_method_name)
174
- assert_equal(copy_method_name,sut_copy.init_copy_method_name)
148
+ describe 'child with copy and unsafe var' do
149
+ before do
150
+ @sut = TestBagChildWithCopyAndUnsafe.new
151
+ @sut_clone = @sut.clone
152
+ @sut_dup = @sut.dup
153
+ end
175
154
 
176
- assert_nil(sut.orig)
155
+ it_does_a_shallow_copy
156
+ it_does_a_deep_copy
177
157
 
178
- if is_safe_copy
179
- assert_same(sut,sut_copy.orig)
180
- else
181
- assert_nil(sut_copy.orig)
182
- end
158
+ it 'does a deep copy of the strs' do
159
+ _(@sut.strs).wont_be_same_as(@sut_clone.strs)
160
+ _(@sut.strs).wont_be_same_as(@sut_dup.strs)
183
161
 
184
- expected = [1,2,3]
162
+ expected = %w[a b c]
185
163
 
186
- assert_same(sut.nums,sut_copy.nums)
187
- assert_equal(expected,sut.nums)
188
- assert_equal(expected,sut_copy.nums)
164
+ _(@sut.strs).must_equal(expected)
165
+ _(@sut_clone.strs).must_equal(expected)
166
+ _(@sut_dup.strs).must_equal(expected)
189
167
 
190
- sut.nums << 4
191
- sut_copy.nums << 5
168
+ @sut.strs << 'd'
169
+ @sut_clone.strs << 'e'
170
+ @sut_dup.strs << 'f'
192
171
 
193
- expected = [1,2,3,4,5]
172
+ _(@sut.strs).must_equal(%w[a b c d])
173
+ _(@sut_clone.strs).must_equal(%w[a b c e])
174
+ _(@sut_dup.strs).must_equal(%w[a b c f])
175
+ end
194
176
 
195
- assert_equal(expected,sut.nums)
196
- assert_equal(expected,sut_copy.nums)
177
+ it 'does not do a deep copy of the unsafe var' do
178
+ _(@sut.unsafe).wont_respond_to(:clone)
179
+ _(@sut.unsafe).wont_respond_to(:dup)
180
+ expect { @sut.unsafe.clone }.must_raise(NoMethodError)
181
+ expect { @sut.unsafe.dup }.must_raise(NoMethodError)
197
182
 
198
- # Reset.
199
- sut.nums.pop(2)
183
+ _(@sut.unsafe).must_be_same_as(@sut_clone.unsafe)
184
+ _(@sut.unsafe).must_be_same_as(@sut_dup.unsafe)
185
+ end
200
186
  end
201
187
  end
202
188
 
203
189
  class TestBag
204
- include InitCopy
190
+ include InitCopy::Able
205
191
 
206
192
  attr_reader :orig
207
193
  attr_reader :nums
@@ -230,13 +216,26 @@ class TestBagWithCopy < TestBag
230
216
  end
231
217
  end
232
218
 
233
- class TestBagWithSafeCopy < TestBag
219
+ class TestBagChildWithCopyAndUnsafe < TestBagWithCopy
220
+ attr_reader :strs
221
+ attr_reader :unsafe
222
+
223
+ def initialize
224
+ super
225
+
226
+ @strs = %w[a b c]
227
+ @unsafe = Class.new do
228
+ undef_method :clone
229
+ undef_method :dup
230
+ end.new
231
+ end
232
+
234
233
  protected
235
234
 
236
- def init_copy(orig)
235
+ def init_copy(*)
237
236
  super
238
237
 
239
- @orig = orig
240
- @nums = ic_copy?(@nums)
238
+ @strs = ic_copy(@strs)
239
+ @unsafe = ic_copy?(@unsafe)
241
240
  end
242
241
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: init_copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Whited
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-06-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Easily use the correct clone or dup method in initialize_copy.
14
13
  email:
@@ -26,6 +25,7 @@ files:
26
25
  - Rakefile
27
26
  - init_copy.gemspec
28
27
  - lib/init_copy.rb
28
+ - lib/init_copy/version.rb
29
29
  - test/init_copy_test.rb
30
30
  homepage: https://github.com/esotericpig/init_copy
31
31
  licenses:
@@ -36,31 +36,33 @@ metadata:
36
36
  source_code_uri: https://github.com/esotericpig/init_copy
37
37
  bug_tracker_uri: https://github.com/esotericpig/init_copy/issues
38
38
  changelog_uri: https://github.com/esotericpig/init_copy/blob/main/CHANGELOG.md
39
- post_install_message:
40
39
  rdoc_options:
41
40
  - "--embed-mixins"
42
41
  - "--hyperlink-all"
43
42
  - "--line-numbers"
44
43
  - "--show-hash"
44
+ - "--encoding"
45
+ - UTF-8
46
+ - "--markup"
47
+ - markdown
45
48
  - "--main"
46
49
  - README.md
47
50
  - "--title"
48
- - InitCopy v0.2.0
51
+ - InitCopy v0.3.1
49
52
  require_paths:
50
53
  - lib
51
54
  required_ruby_version: !ruby/object:Gem::Requirement
52
55
  requirements:
53
56
  - - ">="
54
57
  - !ruby/object:Gem::Version
55
- version: '3.2'
58
+ version: '3.1'
56
59
  required_rubygems_version: !ruby/object:Gem::Requirement
57
60
  requirements:
58
61
  - - ">="
59
62
  - !ruby/object:Gem::Version
60
63
  version: '0'
61
64
  requirements: []
62
- rubygems_version: 3.5.21
63
- signing_key:
65
+ rubygems_version: 3.7.1
64
66
  specification_version: 4
65
67
  summary: Easily use the correct clone or dup method in initialize_copy.
66
68
  test_files: []