core-copy 0.2.1 → 0.3.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/CHANGELOG.md +19 -11
- data/lib/core/copy/version.rb +1 -1
- data/lib/core/copy.rb +81 -2
- metadata +8 -38
- data/lib/is/copyable.rb +0 -24
- data/lib/refine/object/copy.rb +0 -96
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c673ceacedcc039579a823c9d1e0b41c4fd21c17c84205802921302484d69ce2
|
4
|
+
data.tar.gz: 7b543b8b600812f784605e2dd30a3bd8702cb73d9cdb0eef009afd0ec6eb1bc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d97cfdc117866521a3223728ab7580dd42c6809afbfc8d9f2f8277569cdfb6d52a69923ade5ab710ecb92ede0a279f442d66e11983c57c7c15d2511b6817b6
|
7
|
+
data.tar.gz: 9651de66b9f94b29dc2302100d13f344e0893d59ed974e0d5a34d28f55f69bac46642cd31b01100228a43d773c36e6e4e13442161ba5cd855081c8d4c2e974a4
|
data/CHANGELOG.md
CHANGED
@@ -1,32 +1,40 @@
|
|
1
|
-
## [v0.
|
1
|
+
## [v0.3.0](https://github.com/bryanp/corerb/releases/tag/2023-12-24)
|
2
|
+
|
3
|
+
*released on 2023-12-24*
|
4
|
+
|
5
|
+
* `dep` [#143](https://github.com/bryanp/corerb/pull/143) Deprecate `Is::*` and `Refine::*` namespaces ([bryanp](https://github.com/bryanp))
|
6
|
+
* `dep` [#144](https://github.com/bryanp/corerb/pull/144) Remove `Is::Copyable` extension and callback ([bryanp](https://github.com/bryanp))
|
7
|
+
* `dep` [#135](https://github.com/bryanp/corerb/pull/135) Remove Ruby 2 support ([bryanp](https://github.com/bryanp))
|
8
|
+
|
9
|
+
## [v0.2.1](https://github.com/bryanp/corerb/releases/tag/2021-11-02)
|
2
10
|
|
3
11
|
*released on 2021-11-02*
|
4
12
|
|
5
|
-
* `chg` [#97](https://github.com/
|
13
|
+
* `chg` [#97](https://github.com/bryanp/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
|
6
14
|
|
7
|
-
## [v0.2.0](https://github.com/
|
15
|
+
## [v0.2.0](https://github.com/bryanp/corerb/releases/tag/2021-10-24)
|
8
16
|
|
9
17
|
*released on 2021-10-24*
|
10
18
|
|
11
|
-
* `add` [#74](https://github.com/
|
19
|
+
* `add` [#74](https://github.com/bryanp/corerb/pull/74) Introduce a core.copy event ([bryanp](https://github.com/bryanp))
|
12
20
|
|
13
|
-
## [v0.1.0](https://github.com/
|
21
|
+
## [v0.1.0](https://github.com/bryanp/corerb/releases/tag/2021-07-07)
|
14
22
|
|
15
23
|
*released on 2021-07-07*
|
16
24
|
|
17
|
-
* `chg` [#39](https://github.com/
|
25
|
+
* `chg` [#39](https://github.com/bryanp/corerb/pull/39) Drop Ruby 2.6 support from core-copy ([bryanp](https://github.com/bryanp))
|
18
26
|
|
19
|
-
## [v0.0.1](https://github.com/
|
27
|
+
## [v0.0.1](https://github.com/bryanp/corerb/releases/tag/2021-05-22)
|
20
28
|
|
21
29
|
*released on 2021-05-22*
|
22
30
|
|
23
|
-
* `fix` [#33](https://github.com/
|
24
|
-
* `fix` [#32](https://github.com/
|
31
|
+
* `fix` [#33](https://github.com/bryanp/corerb/pull/33) Resolve several differences between supported ruby versions ([bryanp](https://github.com/bryanp))
|
32
|
+
* `fix` [#32](https://github.com/bryanp/corerb/pull/32) Add core-local as a dependency to core-copy ([bryanp](https://github.com/bryanp))
|
25
33
|
|
26
|
-
## [v0.0.0](https://github.com/
|
34
|
+
## [v0.0.0](https://github.com/bryanp/corerb/releases/tag/2021-03-17)
|
27
35
|
|
28
36
|
*released on 2021-03-17*
|
29
37
|
|
30
|
-
* `add` [#19](https://github.com/
|
38
|
+
* `add` [#19](https://github.com/bryanp/corerb/pull/19) Add Refine::Object::Copy for copying objects, arrays, and hashes ([bryanp](https://github.com/bryanp))
|
31
39
|
|
32
40
|
|
data/lib/core/copy/version.rb
CHANGED
data/lib/core/copy.rb
CHANGED
@@ -1,9 +1,88 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "core/local"
|
4
|
+
|
3
5
|
module Core
|
6
|
+
# [public]
|
7
|
+
#
|
4
8
|
module Copy
|
5
9
|
require_relative "copy/version"
|
10
|
+
|
11
|
+
DEFAULT = Object.new
|
12
|
+
|
13
|
+
refine Object do
|
14
|
+
# [public] Copies the object using `clone`.
|
15
|
+
#
|
16
|
+
def copy(freeze: DEFAULT)
|
17
|
+
clone(freeze: resolve_freeze_argument(freeze))
|
18
|
+
end
|
19
|
+
|
20
|
+
private def resolve_freeze_argument(value)
|
21
|
+
case value
|
22
|
+
when DEFAULT
|
23
|
+
frozen?
|
24
|
+
else
|
25
|
+
!!value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
refine Array do
|
31
|
+
# [public] Copies the array, along with each value.
|
32
|
+
#
|
33
|
+
def copy(freeze: DEFAULT)
|
34
|
+
unless Copy.copying?(self)
|
35
|
+
Copy.prevent_recursion(self) do
|
36
|
+
array = map { |value|
|
37
|
+
value.copy(freeze: freeze)
|
38
|
+
}
|
39
|
+
|
40
|
+
array.freeze if resolve_freeze_argument(freeze)
|
41
|
+
|
42
|
+
array
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
refine Hash do
|
49
|
+
# [public] Copies the hash, along with each key and value.
|
50
|
+
#
|
51
|
+
def copy(freeze: DEFAULT)
|
52
|
+
unless Copy.copying?(self)
|
53
|
+
Copy.prevent_recursion(self) do
|
54
|
+
hash = {}
|
55
|
+
|
56
|
+
each_pair do |key, value|
|
57
|
+
hash[key.copy(freeze: freeze)] = value.copy(freeze: freeze)
|
58
|
+
end
|
59
|
+
|
60
|
+
hash.freeze if resolve_freeze_argument(freeze)
|
61
|
+
|
62
|
+
hash
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
include Core::Local
|
70
|
+
|
71
|
+
def prevent_recursion(object)
|
72
|
+
object_id = object.object_id
|
73
|
+
copied_objects[object_id] = true
|
74
|
+
yield
|
75
|
+
ensure
|
76
|
+
copied_objects.delete(object_id)
|
77
|
+
end
|
78
|
+
|
79
|
+
def copying?(object)
|
80
|
+
copied_objects[object.object_id]
|
81
|
+
end
|
82
|
+
|
83
|
+
def copied_objects
|
84
|
+
localized(:__corerb_copied_objects__) || localize(:__corerb_copied_objects__, {})
|
85
|
+
end
|
86
|
+
end
|
6
87
|
end
|
7
88
|
end
|
8
|
-
|
9
|
-
require_relative "../refine/object/copy"
|
metadata
CHANGED
@@ -1,59 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core-copy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: core-event
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: core-extension
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.3'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.3'
|
41
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: core-local
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
44
16
|
requirements:
|
45
17
|
- - "~>"
|
46
18
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
19
|
+
version: '0.2'
|
48
20
|
type: :runtime
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
24
|
- - "~>"
|
53
25
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
26
|
+
version: '0.2'
|
55
27
|
description: Manage how internal object state is copied.
|
56
|
-
email: bryan@
|
28
|
+
email: bryan@bryanp.org
|
57
29
|
executables: []
|
58
30
|
extensions: []
|
59
31
|
extra_rdoc_files: []
|
@@ -62,9 +34,7 @@ files:
|
|
62
34
|
- LICENSE
|
63
35
|
- lib/core/copy.rb
|
64
36
|
- lib/core/copy/version.rb
|
65
|
-
|
66
|
-
- lib/refine/object/copy.rb
|
67
|
-
homepage: https://github.com/metabahn/corerb/
|
37
|
+
homepage: https://github.com/bryanp/corerb/
|
68
38
|
licenses:
|
69
39
|
- MPL-2.0
|
70
40
|
metadata: {}
|
@@ -76,14 +46,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
46
|
requirements:
|
77
47
|
- - ">="
|
78
48
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
49
|
+
version: '3.0'
|
80
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
51
|
requirements:
|
82
52
|
- - ">="
|
83
53
|
- !ruby/object:Gem::Version
|
84
54
|
version: '0'
|
85
55
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
56
|
+
rubygems_version: 3.5.1
|
87
57
|
signing_key:
|
88
58
|
specification_version: 4
|
89
59
|
summary: Manage how internal object state is copied.
|
data/lib/is/copyable.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "is/eventable"
|
4
|
-
require "is/extension"
|
5
|
-
|
6
|
-
module Is
|
7
|
-
module Copyable
|
8
|
-
extend Is::Extension
|
9
|
-
|
10
|
-
applies do
|
11
|
-
event "core.copy"
|
12
|
-
end
|
13
|
-
|
14
|
-
extends dependencies: [Is::Eventable]
|
15
|
-
|
16
|
-
extends :implementation, prepend: true do
|
17
|
-
def initialize_copy(...)
|
18
|
-
performing "core.copy" do
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/refine/object/copy.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "core/local"
|
4
|
-
|
5
|
-
module Refine
|
6
|
-
module Object
|
7
|
-
module Copy
|
8
|
-
DEFAULT = ::Object.new
|
9
|
-
|
10
|
-
refine ::Object do
|
11
|
-
# [public] Copies the object using `clone`.
|
12
|
-
#
|
13
|
-
if RbConfig::CONFIG["RUBY_PROGRAM_VERSION"] < "3"
|
14
|
-
def copy(freeze: DEFAULT)
|
15
|
-
should_freeze = resolve_freeze_argument(freeze)
|
16
|
-
|
17
|
-
value = clone(freeze: should_freeze)
|
18
|
-
value.freeze if should_freeze
|
19
|
-
value
|
20
|
-
end
|
21
|
-
else
|
22
|
-
def copy(freeze: DEFAULT)
|
23
|
-
clone(freeze: resolve_freeze_argument(freeze))
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private def resolve_freeze_argument(value)
|
28
|
-
case value
|
29
|
-
when DEFAULT
|
30
|
-
frozen?
|
31
|
-
else
|
32
|
-
!!value
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
refine Array do
|
38
|
-
# [public] Copies the array, along with each value.
|
39
|
-
#
|
40
|
-
def copy(freeze: DEFAULT)
|
41
|
-
unless Copy.copying?(self)
|
42
|
-
Copy.prevent_recursion(self) do
|
43
|
-
array = map { |value|
|
44
|
-
value.copy(freeze: freeze)
|
45
|
-
}
|
46
|
-
|
47
|
-
array.freeze if resolve_freeze_argument(freeze)
|
48
|
-
|
49
|
-
array
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
refine Hash do
|
56
|
-
# [public] Copies the hash, along with each key and value.
|
57
|
-
#
|
58
|
-
def copy(freeze: DEFAULT)
|
59
|
-
unless Copy.copying?(self)
|
60
|
-
Copy.prevent_recursion(self) do
|
61
|
-
hash = {}
|
62
|
-
|
63
|
-
each_pair do |key, value|
|
64
|
-
hash[key.copy(freeze: freeze)] = value.copy(freeze: freeze)
|
65
|
-
end
|
66
|
-
|
67
|
-
hash.freeze if resolve_freeze_argument(freeze)
|
68
|
-
|
69
|
-
hash
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class << self
|
76
|
-
include Is::Localized
|
77
|
-
|
78
|
-
def prevent_recursion(object)
|
79
|
-
object_id = object.object_id
|
80
|
-
copied_objects[object_id] = true
|
81
|
-
yield
|
82
|
-
ensure
|
83
|
-
copied_objects.delete(object_id)
|
84
|
-
end
|
85
|
-
|
86
|
-
def copying?(object)
|
87
|
-
copied_objects[object.object_id]
|
88
|
-
end
|
89
|
-
|
90
|
-
def copied_objects
|
91
|
-
localized(:__corerb_copied_objects__) || localize(:__corerb_copied_objects__, {})
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|