core-state 0.1.3 → 0.1.7

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: 1256eb4ef3acf8b61a7754d8ea30ce644f7fc081132a3d9f107a40deca79ed0a
4
- data.tar.gz: f65aa78f287f521a729723823f04339153d0a80cf8291e82e4a1c791cc57745e
3
+ metadata.gz: 057a6a05e3723b496411920e3ab4776487985a2b68812bb1674fbf6cd637beb7
4
+ data.tar.gz: 891cc1ba332a5e157cd3f501b6361426a2985558b1079e6ac7c2eebae355ac72
5
5
  SHA512:
6
- metadata.gz: 1669bdf575ac48ed4abb7523383d2a8ae39a6f52fd6b08143b3ef48bd89698e9492f9f16ffff1538329a35989ec57bde2db1b77e2d67e1cafc89bd33896788e4
7
- data.tar.gz: 1cda2c4017dccf2c9e9d9c935d48c95d6aeeda0c471f662d5618b723b54d08d921bae78849e3aa5fd7783716402edbc8d8726a5638c83992e318db45be4c2a27
6
+ metadata.gz: 5558c6a88f115482c0a86026405179206f0ce4b5f35ef47f22891d59722b3f12175445b6ba8a2b2551531e0bb79316ada7ae4431ecebaa7cc6458db219dd0b10
7
+ data.tar.gz: 80d3597facff509323fec18c1926ae45eb2ecb3e8bfbe8c08d903a7757371b11f50be989275da1b9bd161358f7366ceee4630cfae2e8facca79e7f5d3360e8cc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## [v0.1.7](https://github.com/metabahn/corerb/releases/tag/2021-11-23.1)
2
+
3
+ *released on 2021-11-23.1*
4
+
5
+ * `chg` [#109](https://github.com/metabahn/corerb/pull/109) Prefer `__send__` to `send` ([bryanp](https://github.com/bryanp))
6
+
7
+ ## [v0.1.6](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
8
+
9
+ *released on 2021-11-02*
10
+
11
+ * `chg` [#97](https://github.com/metabahn/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
12
+
13
+ ## [v0.1.5](https://github.com/metabahn/corerb/releases/tag/2021-10-22)
14
+
15
+ *released on 2021-10-22*
16
+
17
+ * `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))
18
+
19
+ ## [v0.1.4](https://github.com/metabahn/corerb/releases/tag/2021-09-30)
20
+
21
+ *released on 2021-09-30*
22
+
23
+ * `fix` [#85](https://github.com/metabahn/corerb/pull/85) Initialize with class-level state when available ([bryanp](https://github.com/bryanp))
24
+
1
25
  ## [v0.1.3](https://github.com/metabahn/corerb/releases/tag/2021-09-28)
2
26
 
3
27
  *released on 2021-09-28*
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module State
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.7"
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
@@ -187,22 +185,24 @@ module Is
187
185
  end
188
186
  end
189
187
 
190
- subclass.send(:prepend_defined_state_modules)
191
- subclass.instance_variable_set("@__defined_state", @__defined_state.dup)
188
+ subclass.__send__(:prepend_defined_state_modules)
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
@@ -259,11 +264,11 @@ module Is
259
264
  # [public] Safely mutates state by name, yielding a copy of the current value to the block.
260
265
  #
261
266
  def mutate_state(name, &block)
262
- send("#{name}=", block.call(send(name)))
267
+ __send__("#{name}=", block.call(__send__(name)))
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.3
4
+ version: 0.1.7
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-09-29 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension