core-extension 0.4.2 → 0.5.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
  SHA256:
3
- metadata.gz: 0b882e25ffe74f245ebcd38369851bda318f3fad902df7dd7a524be88811ed07
4
- data.tar.gz: ecfecfd22eb616117f4e66e08e0c16b9f2187c13cfd3869b4cd1ca2d6df444da
3
+ metadata.gz: 45681dd9b4eb444ef89b1f1f9688a0f091c6bf1aab6554d084b2f3f71a6ef40c
4
+ data.tar.gz: a7611a830a7b0b6d29f60accf80034e6fc06c288471d96708c1b82e2fc86c436
5
5
  SHA512:
6
- metadata.gz: 70850ea99d13d19474fb6cdc2fd71a38c85b31057be497dc2953f1e3c721acce1a74dc98f9f62d5931567146d6861f081ecc1d679da12192728083941175ef4b
7
- data.tar.gz: 512063dbcdc3fbd9c8a7dcde8dfe10fc39bddc97cdc816ba6423dd36d81d4e1153eb4d0ae838a43df295888a6190976570b785790d168241d9288c1bc8aa21d7
6
+ metadata.gz: f14e4ece467c33af911e8bea83b424bf85ce15980f427f1a56326b7263f840a1cfd77a10aeea041950acda7f8fb2b321bc1e76470061b4ded945de7da2887db8
7
+ data.tar.gz: fe4d73140a8649f7ae8ec2236666a0b1c4316a2ca17d6287fa154939d008bc35d600421590d8e75b59e552bc52c4d1fc2142b47bd440596b2ba17cedf5e99781
data/CHANGELOG.md CHANGED
@@ -1,47 +1,55 @@
1
- ## [v0.4.2](https://github.com/metabahn/corerb/releases/tag/2021-11-23)
1
+ ## [v0.5.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` [#142](https://github.com/bryanp/corerb/pull/142) Remove copy behavior from extensions ([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.4.2](https://github.com/bryanp/corerb/releases/tag/2021-11-23)
2
10
 
3
11
  *released on 2021-11-23*
4
12
 
5
- * `fix` [#108](https://github.com/metabahn/corerb/pull/108) Prevent extension dependencies from extending an object twice ([bryanp](https://github.com/bryanp))
13
+ * `fix` [#108](https://github.com/bryanp/corerb/pull/108) Prevent extension dependencies from extending an object twice ([bryanp](https://github.com/bryanp))
6
14
 
7
- ## [v0.4.1](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
15
+ ## [v0.4.1](https://github.com/bryanp/corerb/releases/tag/2021-11-02)
8
16
 
9
17
  *released on 2021-11-02*
10
18
 
11
- * `chg` [#97](https://github.com/metabahn/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
19
+ * `chg` [#97](https://github.com/bryanp/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
12
20
 
13
- ## [v0.4.0](https://github.com/metabahn/corerb/releases/tag/2021-10-24)
21
+ ## [v0.4.0](https://github.com/bryanp/corerb/releases/tag/2021-10-24)
14
22
 
15
23
  *released on 2021-10-24*
16
24
 
17
- * `add` [#86](https://github.com/metabahn/corerb/pull/86) Copy instance variables when cloning an extension ([bryanp](https://github.com/bryanp))
25
+ * `add` [#86](https://github.com/bryanp/corerb/pull/86) Copy instance variables when cloning an extension ([bryanp](https://github.com/bryanp))
18
26
 
19
- ## [v0.3.0](https://github.com/metabahn/corerb/releases/tag/2021-07-15)
27
+ ## [v0.3.0](https://github.com/bryanp/corerb/releases/tag/2021-07-15)
20
28
 
21
29
  *released on 2021-07-15*
22
30
 
23
- * `chg` [#72](https://github.com/metabahn/corerb/pull/72) Rename extension dependency flags ([bryanp](https://github.com/bryanp))
24
- * `chg` [#71](https://github.com/metabahn/corerb/pull/71) Rename Is::Extension::applied to applies ([bryanp](https://github.com/bryanp))
25
- * `chg` [#68](https://github.com/metabahn/corerb/pull/68) Pass the extension scope to apply blocks ([bryanp](https://github.com/bryanp))
26
- * `chg` [#67](https://github.com/metabahn/corerb/pull/67) Refactor extend support for extensions ([bryanp](https://github.com/bryanp))
27
- * `chg` [#66](https://github.com/metabahn/corerb/pull/66) Support extending classes with extensions ([bryanp](https://github.com/bryanp))
31
+ * `chg` [#72](https://github.com/bryanp/corerb/pull/72) Rename extension dependency flags ([bryanp](https://github.com/bryanp))
32
+ * `chg` [#71](https://github.com/bryanp/corerb/pull/71) Rename Is::Extension::applied to applies ([bryanp](https://github.com/bryanp))
33
+ * `chg` [#68](https://github.com/bryanp/corerb/pull/68) Pass the extension scope to apply blocks ([bryanp](https://github.com/bryanp))
34
+ * `chg` [#67](https://github.com/bryanp/corerb/pull/67) Refactor extend support for extensions ([bryanp](https://github.com/bryanp))
35
+ * `chg` [#66](https://github.com/bryanp/corerb/pull/66) Support extending classes with extensions ([bryanp](https://github.com/bryanp))
28
36
 
29
- ## [v0.2.0](https://github.com/metabahn/corerb/releases/tag/2021-07-07)
37
+ ## [v0.2.0](https://github.com/bryanp/corerb/releases/tag/2021-07-07)
30
38
 
31
39
  *released on 2021-07-07*
32
40
 
33
- * `chg` [#40](https://github.com/metabahn/corerb/pull/40) Drop Ruby 2.6 support from core-extension ([bryanp](https://github.com/bryanp))
41
+ * `chg` [#40](https://github.com/bryanp/corerb/pull/40) Drop Ruby 2.6 support from core-extension ([bryanp](https://github.com/bryanp))
34
42
 
35
- ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-02-10)
43
+ ## [v0.1.0](https://github.com/bryanp/corerb/releases/tag/2021-02-10)
36
44
 
37
45
  *released on 2021-02-10*
38
46
 
39
- * `chg` [#3](https://github.com/metabahn/corerb/pull/3) Apply extension dependencies before behavior ([bryanp](https://github.com/bryanp))
47
+ * `chg` [#3](https://github.com/bryanp/corerb/pull/3) Apply extension dependencies before behavior ([bryanp](https://github.com/bryanp))
40
48
 
41
- ## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2020-12-29)
49
+ ## [v0.0.0](https://github.com/bryanp/corerb/releases/tag/2020-12-29)
42
50
 
43
51
  *released on 2020-12-29*
44
52
 
45
- * `add` [#1](https://github.com/metabahn/corerb/pull/2) Initial core-extension behavior ([bryanp](https://github.com/bryanp))
53
+ * `add` [#1](https://github.com/bryanp/corerb/pull/2) Initial core-extension behavior ([bryanp](https://github.com/bryanp))
46
54
 
47
55
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Extension
5
- VERSION = "0.4.2"
5
+ VERSION = "0.5.0"
6
6
 
7
7
  def self.version
8
8
  VERSION
@@ -1,10 +1,105 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Core
4
+ # [public] Turn a module into a mixin with superpowers.
5
+ #
4
6
  module Extension
5
7
  require_relative "extension/behavior"
8
+ require_relative "extension/dependency"
6
9
  require_relative "extension/version"
10
+
11
+ # [public] Restrict the extension to one or more object types.
12
+ #
13
+ def restrict(*types)
14
+ allowed_types.concat(types).uniq!
15
+ end
16
+
17
+ # [public] Define a module to be extended or included into objects that include this extension.
18
+ #
19
+ def extends(*flags, dependencies: [], prepend: false, &block)
20
+ dependencies.each do |dependency|
21
+ defined_dependencies << Core::Extension::Dependency.new(*flags, dependency: dependency, prepend: prepend)
22
+ end
23
+
24
+ if block
25
+ defined_dependencies << Core::Extension::Dependency.new(*flags, dependency: Module.new(&block), prepend: prepend)
26
+ end
27
+ end
28
+
29
+ # [public] Define behavior to be evaled on objects that include this extension.
30
+ #
31
+ def applies(force: false, &block)
32
+ defined_behaviors << Core::Extension::Behavior.new(force: force, &block)
33
+ end
34
+
35
+ def extended(base)
36
+ enforce_allowed_types(base)
37
+ extend_defined_dependencies(base)
38
+ extend_defined_behaviors(base)
39
+
40
+ super
41
+ end
42
+
43
+ def included(base)
44
+ enforce_allowed_types(base)
45
+ include_defined_dependencies(base)
46
+ include_defined_behaviors(base)
47
+
48
+ super
49
+ end
50
+
51
+ private def enforce_allowed_types(object)
52
+ return if allowed?(object)
53
+
54
+ raise TypeError, "Expected `#{object}' to be a decendent of an allowed type: #{allowed_types_string}"
55
+ end
56
+
57
+ private def allowed_types_string
58
+ allowed_types.map { |allowed_type|
59
+ "`#{allowed_type.inspect}'"
60
+ }.join(", ")
61
+ end
62
+
63
+ private def allowed?(object)
64
+ allowed_types.empty? || allowed_types.any? { |allowed_type|
65
+ object <= allowed_type
66
+ }
67
+ end
68
+
69
+ private def extend_defined_behaviors(object)
70
+ defined_behaviors.each do |behavior|
71
+ behavior.apply_extend(object)
72
+ end
73
+ end
74
+
75
+ private def extend_defined_dependencies(object)
76
+ defined_dependencies.each do |dependency|
77
+ dependency.apply_extend(object)
78
+ end
79
+ end
80
+
81
+ private def include_defined_behaviors(object)
82
+ defined_behaviors.each do |behavior|
83
+ behavior.apply_include(object)
84
+ end
85
+ end
86
+
87
+ private def include_defined_dependencies(object)
88
+ defined_dependencies.each do |dependency|
89
+ dependency.apply_include(object)
90
+ end
91
+ end
92
+
93
+ private def allowed_types
94
+ @__allowed_types__ ||= []
95
+ end
96
+
97
+ private def defined_behaviors
98
+ @__defined_behaviors__ ||= []
99
+ end
100
+
101
+ private def defined_dependencies
102
+ @__defined_dependencies__ ||= []
103
+ end
7
104
  end
8
105
  end
9
-
10
- require_relative "../is/extension"
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.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: 2021-11-23 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create mixins with superpowers.
14
- email: bryan@metabahn.com
14
+ email: bryan@bryanp.org
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
@@ -22,8 +22,7 @@ files:
22
22
  - lib/core/extension/behavior.rb
23
23
  - lib/core/extension/dependency.rb
24
24
  - lib/core/extension/version.rb
25
- - lib/is/extension.rb
26
- homepage: https://github.com/metabahn/corerb/
25
+ homepage: https://github.com/bryanp/corerb/
27
26
  licenses:
28
27
  - MPL-2.0
29
28
  metadata: {}
@@ -35,14 +34,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
34
  requirements:
36
35
  - - ">="
37
36
  - !ruby/object:Gem::Version
38
- version: '2.7'
37
+ version: '3.0'
39
38
  required_rubygems_version: !ruby/object:Gem::Requirement
40
39
  requirements:
41
40
  - - ">="
42
41
  - !ruby/object:Gem::Version
43
42
  version: '0'
44
43
  requirements: []
45
- rubygems_version: 3.2.22
44
+ rubygems_version: 3.5.1
46
45
  signing_key:
47
46
  specification_version: 4
48
47
  summary: Create mixins with superpowers.
data/lib/is/extension.rb DELETED
@@ -1,199 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../core/extension/behavior"
4
- require_relative "../core/extension/dependency"
5
-
6
- module Is
7
- # [public] Turn a module into a mixin with superpowers.
8
- #
9
- module Extension
10
- # Adding core-copy as a dependency creates a recursive dependency, so just bundle it.
11
- #
12
- module Copy
13
- DEFAULT = ::Object.new
14
-
15
- refine ::Object do
16
- if RbConfig::CONFIG["RUBY_PROGRAM_VERSION"] < "3"
17
- def copy(freeze: DEFAULT)
18
- should_freeze = resolve_freeze_argument(freeze)
19
-
20
- value = clone(freeze: should_freeze)
21
- value.freeze if should_freeze
22
- value
23
- end
24
- else
25
- def copy(freeze: DEFAULT)
26
- clone(freeze: resolve_freeze_argument(freeze))
27
- end
28
- end
29
-
30
- private def resolve_freeze_argument(value)
31
- case value
32
- when DEFAULT
33
- frozen?
34
- else
35
- !!value
36
- end
37
- end
38
- end
39
-
40
- refine Array do
41
- def copy(freeze: DEFAULT)
42
- unless Extension.copying?(self)
43
- Extension.prevent_recursion(self) do
44
- array = map { |value|
45
- value.copy(freeze: freeze)
46
- }
47
-
48
- array.freeze if resolve_freeze_argument(freeze)
49
-
50
- array
51
- end
52
- end
53
- end
54
- end
55
-
56
- refine Hash do
57
- def copy(freeze: DEFAULT)
58
- unless Extension.copying?(self)
59
- Extension.prevent_recursion(self) do
60
- hash = {}
61
-
62
- each_pair do |key, value|
63
- hash[key.copy(freeze: freeze)] = value.copy(freeze: freeze)
64
- end
65
-
66
- hash.freeze if resolve_freeze_argument(freeze)
67
-
68
- hash
69
- end
70
- end
71
- end
72
- end
73
- end
74
-
75
- class << self
76
- def prevent_recursion(object)
77
- object_id = object.object_id
78
- copied_objects[object_id] = true
79
- yield
80
- ensure
81
- copied_objects.delete(object_id)
82
- end
83
-
84
- def copying?(object)
85
- copied_objects[object.object_id]
86
- end
87
-
88
- def copied_objects
89
- # We can't use core-local because it would create a recursive dependency.
90
- #
91
- Thread.current["__corerb_localized_#{object_id}__corerb_copied_objects__"] ||= {}
92
- end
93
- end
94
-
95
- using Copy
96
-
97
- def initialize_copy(...)
98
- super
99
-
100
- instance_variables.each do |instance_variable|
101
- instance_variable_set(instance_variable, instance_variable_get(instance_variable).copy)
102
- end
103
- end
104
-
105
- # [public] Restrict the extension to one or more object types.
106
- #
107
- def restrict(*types)
108
- allowed_types.concat(types).uniq!
109
- end
110
-
111
- # [public] Define a module to be extended or included into objects that include this extension.
112
- #
113
- def extends(*flags, dependencies: [], prepend: false, &block)
114
- dependencies.each do |dependency|
115
- defined_dependencies << Core::Extension::Dependency.new(*flags, dependency: dependency, prepend: prepend)
116
- end
117
-
118
- if block
119
- defined_dependencies << Core::Extension::Dependency.new(*flags, dependency: Module.new(&block), prepend: prepend)
120
- end
121
- end
122
-
123
- # [public] Define behavior to be evaled on objects that include this extension.
124
- #
125
- def applies(force: false, &block)
126
- defined_behaviors << Core::Extension::Behavior.new(force: force, &block)
127
- end
128
-
129
- def extended(base)
130
- enforce_allowed_types(base)
131
- extend_defined_dependencies(base)
132
- extend_defined_behaviors(base)
133
-
134
- super
135
- end
136
-
137
- def included(base)
138
- enforce_allowed_types(base)
139
- include_defined_dependencies(base)
140
- include_defined_behaviors(base)
141
-
142
- super
143
- end
144
-
145
- private def enforce_allowed_types(object)
146
- return if allowed?(object)
147
-
148
- raise TypeError, "Expected `#{object}' to be a decendent of an allowed type: #{allowed_types_string}"
149
- end
150
-
151
- private def allowed_types_string
152
- allowed_types.map { |allowed_type|
153
- "`#{allowed_type.inspect}'"
154
- }.join(", ")
155
- end
156
-
157
- private def allowed?(object)
158
- allowed_types.empty? || allowed_types.any? { |allowed_type|
159
- object <= allowed_type
160
- }
161
- end
162
-
163
- private def extend_defined_behaviors(object)
164
- defined_behaviors.each do |behavior|
165
- behavior.apply_extend(object)
166
- end
167
- end
168
-
169
- private def extend_defined_dependencies(object)
170
- defined_dependencies.each do |dependency|
171
- dependency.apply_extend(object)
172
- end
173
- end
174
-
175
- private def include_defined_behaviors(object)
176
- defined_behaviors.each do |behavior|
177
- behavior.apply_include(object)
178
- end
179
- end
180
-
181
- private def include_defined_dependencies(object)
182
- defined_dependencies.each do |dependency|
183
- dependency.apply_include(object)
184
- end
185
- end
186
-
187
- private def allowed_types
188
- @__allowed_types__ ||= []
189
- end
190
-
191
- private def defined_behaviors
192
- @__defined_behaviors__ ||= []
193
- end
194
-
195
- private def defined_dependencies
196
- @__defined_dependencies__ ||= []
197
- end
198
- end
199
- end