core-state 0.1.2 → 0.1.6

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: 53361d09b54352ddbb50524bef81c5f6aba042e4770f1f8988a110e86f706b1d
4
- data.tar.gz: 5d08a756908ce47e59bdfdd58ed96ddc71cbf12d148e44e1a0079724ceb0551b
3
+ metadata.gz: 4d8e18bc4a17547fa9177a538b991388f3e98dd37dcb98e6d87e76ac56c10b67
4
+ data.tar.gz: 9f6662fa3ed3d8c45495c5f3d07135e84323ea929d0725c2292b0fc3cdcb5b6a
5
5
  SHA512:
6
- metadata.gz: 8e575916779181a6cbe28a2a82333b5dea39cd41b7a2e863e25aa72fa1082115ef82fc8c60a0c9e9335f673362c18f0a9f1ca447070038995c36556b78d7a23a
7
- data.tar.gz: 2d52fdd9fe0dba779271a9cbc095467fd98d705fe60f70edf35acab02b25537f9a5c4946d30b94e3c22222683d20af76e7e4179956bb1c4e5cc30e8e8ad3459a
6
+ metadata.gz: ea6cbfec043568a05545f37a06407b869c484072043b45a16d7c6d7e52bfed2e00f9b6629c8ac14d898f4970c3415f4d286350f86fab8573cf2184c2ec227a3c
7
+ data.tar.gz: 86e0e24ac6324a28ddcf1153e10cfb5f65efe06a79240fef3d159f4bf851ebb1d81e2a8e6b0bb7aa496ddc7116faaae657aa1da06b1b7cf88bd91aea39a86b32
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## [v0.1.6](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
2
+
3
+ *released on 2021-11-02*
4
+
5
+ * `chg` [#97](https://github.com/metabahn/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
6
+
7
+ ## [v0.1.5](https://github.com/metabahn/corerb/releases/tag/2021-10-22)
8
+
9
+ *released on 2021-10-22*
10
+
11
+ * `fix` [#88](https://github.com/metabahn/corerb/pull/88) Fix an issue causing state to be shared between sibling subclasses ([bryanp](https://github.com/bryanp))
12
+
13
+ ## [v0.1.4](https://github.com/metabahn/corerb/releases/tag/2021-09-30)
14
+
15
+ *released on 2021-09-30*
16
+
17
+ * `fix` [#85](https://github.com/metabahn/corerb/pull/85) Initialize with class-level state when available ([bryanp](https://github.com/bryanp))
18
+
19
+ ## [v0.1.3](https://github.com/metabahn/corerb/releases/tag/2021-09-28)
20
+
21
+ *released on 2021-09-28*
22
+
23
+ * `fix` [#84](https://github.com/metabahn/corerb/pull/84) Define core-local as a dependency of core-state ([bryanp](https://github.com/bryanp))
24
+
1
25
  ## [v0.1.1](https://github.com/metabahn/corerb/releases/tag/2021-07-15)
2
26
 
3
27
  *released on 2021-07-15*
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module State
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.6"
6
6
 
7
7
  def self.version
8
8
  VERSION
data/lib/is/stateful.rb CHANGED
@@ -7,14 +7,12 @@ module Is
7
7
  # [public] Makes objects stateful.
8
8
  #
9
9
  module Stateful
10
- # Adding core-copy as a dependency of core-state creates a recursive dependency, so just bundle it.
10
+ # Adding core-copy as a dependency creates a recursive dependency, so just bundle it.
11
11
  #
12
12
  module Copy
13
13
  DEFAULT = ::Object.new
14
14
 
15
15
  refine ::Object do
16
- # [public] Copies the object using `clone`.
17
- #
18
16
  if RbConfig::CONFIG["RUBY_PROGRAM_VERSION"] < "3"
19
17
  def copy(freeze: DEFAULT)
20
18
  should_freeze = resolve_freeze_argument(freeze)
@@ -40,8 +38,6 @@ module Is
40
38
  end
41
39
 
42
40
  refine Array do
43
- # [public] Copies the array, along with each value.
44
- #
45
41
  def copy(freeze: DEFAULT)
46
42
  unless Stateful.copying?(self)
47
43
  Stateful.prevent_recursion(self) do
@@ -58,8 +54,6 @@ module Is
58
54
  end
59
55
 
60
56
  refine Hash do
61
- # [public] Copies the hash, along with each key and value.
62
- #
63
57
  def copy(freeze: DEFAULT)
64
58
  unless Stateful.copying?(self)
65
59
  Stateful.prevent_recursion(self) do
@@ -122,6 +116,10 @@ module Is
122
116
  defined_state[ivar_name] = state
123
117
  defined_state_isolations << ivar_name
124
118
 
119
+ if state[:class]
120
+ instance_variable_set(ivar_name, default)
121
+ end
122
+
125
123
  prefix = if private
126
124
  "private "
127
125
  else
@@ -188,21 +186,23 @@ module Is
188
186
  end
189
187
 
190
188
  subclass.send(:prepend_defined_state_modules)
191
- subclass.instance_variable_set("@__defined_state", @__defined_state.dup)
189
+ subclass.instance_variable_set("@__defined_state__", @__defined_state__.each_with_object({}) { |(key, value), state|
190
+ state[key] = value.dup
191
+ })
192
192
 
193
193
  super
194
194
  end
195
195
 
196
196
  private def defined_state
197
- @__defined_state ||= {}
197
+ @__defined_state__ ||= {}
198
198
  end
199
199
 
200
200
  private def defined_state_class_module
201
- @__defined_state_class_module ||= Module.new
201
+ @__defined_state_class_module__ ||= Module.new
202
202
  end
203
203
 
204
204
  private def defined_state_instance_module
205
- @__defined_state_instance_module ||= Module.new
205
+ @__defined_state_instance_module__ ||= Module.new
206
206
  end
207
207
 
208
208
  private def prepend_defined_state_modules
@@ -239,9 +239,14 @@ module Is
239
239
 
240
240
  extends :implementation, prepend: true do
241
241
  def initialize(...)
242
- self.class.send(:defined_state).each_pair do |name, state|
242
+ self_class = self.class
243
+ self_class.send(:defined_state).each_pair do |name, state|
243
244
  if state[:instance]
244
- instance_variable_set(name, state[:value])
245
+ if state[:class]
246
+ instance_variable_set(name, self_class.instance_variable_get(name))
247
+ else
248
+ instance_variable_set(name, state[:value])
249
+ end
245
250
  end
246
251
  end
247
252
 
@@ -249,7 +254,7 @@ module Is
249
254
  end
250
255
 
251
256
  def initialize_copy(...)
252
- @__defined_state_isolations = []
257
+ @__defined_state_isolations__ = []
253
258
 
254
259
  super
255
260
  end
@@ -263,7 +268,7 @@ module Is
263
268
  end
264
269
 
265
270
  private def defined_state_isolations
266
- @__defined_state_isolations ||= []
271
+ @__defined_state_isolations__ ||= []
267
272
  end
268
273
  end
269
274
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.6
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-07-16 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: core-local
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  description: Easily manage object state.
28
42
  email: bryan@metabahn.com
29
43
  executables: []
@@ -54,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
56
70
  requirements: []
57
- rubygems_version: 3.2.15
71
+ rubygems_version: 3.2.22
58
72
  signing_key:
59
73
  specification_version: 4
60
74
  summary: Easily manage object state.