wholeable 2.0.0 → 2.2.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
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +50 -28
- data/wholeable.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +13 -13
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 449fc75d34cc505190e11670452eed7f8a1f58d7f24f2df36fe24857f055a188
|
|
4
|
+
data.tar.gz: c958dca76cc2446384579ec537961f77da10c40680c71b10768335dead1f919e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d551292b8f50f38f9fccfa1bae6a8e9ff174c82a76106f94dac6f748a4cff6a8bf1628d296455b8b3a61ceef0752e70ce709255195477b5f4ab57c8792620e5
|
|
7
|
+
data.tar.gz: f143f59acccf45cfd19042715d6ad3d0619a2755a28e6c7b39f2288aa0cde174454cec77c6864b8e7418c2ef662883669eb94b1cb2b1d1fda2961c9b7a370590
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.adoc
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
= Wholeable
|
|
12
12
|
|
|
13
|
-
Wholeable allows you to turn your object into a _whole value object_ by ensuring object equality is determined by the values of the object instead of
|
|
13
|
+
Wholeable allows you to turn your object into a _whole value object_ by ensuring object equality is determined by the values of the object instead of object identity. Whole value objects -- or value objects in general -- have the following traits:
|
|
14
14
|
|
|
15
15
|
* Equality is determined by the values that make up an object and not by link:https://en.wikipedia.org/wiki/Identity_(object-oriented_programming)[identity] (i.e. memory address) which is the default behavior for all {ruby_link} objects except for {data_link} and {structs_link}.
|
|
16
|
-
* Identity remains unique since two objects can have the same values but different identity. This means `BasicObject#equal?` is never overwritten -- which is strongly discouraged -- as per link:https://
|
|
16
|
+
* Identity remains unique since two objects can have the same values but different identity. This means `BasicObject#equal?` is never overwritten -- which is strongly discouraged -- as per link:https://docs.ruby-lang.org/en/master/BasicObject.html[BasicObject] documentation.
|
|
17
17
|
* Value objects should be immutable (i.e. frozen) by default. This implementation enforces a strict adherence to immutability in order to ensure value objects remain equal and discourage mutation.
|
|
18
18
|
|
|
19
19
|
toc::[]
|
|
@@ -70,6 +70,8 @@ To use, include Wholeable along with a list of attributes that make up your whol
|
|
|
70
70
|
|
|
71
71
|
[source,ruby]
|
|
72
72
|
----
|
|
73
|
+
require "wholeable"
|
|
74
|
+
|
|
73
75
|
class Person
|
|
74
76
|
include Wholeable[:name, :email]
|
|
75
77
|
|
|
@@ -162,10 +164,12 @@ Both methods work but use `.[]` when supplying arguments and `.new` when you don
|
|
|
162
164
|
|
|
163
165
|
=== Mutability
|
|
164
166
|
|
|
165
|
-
|
|
167
|
+
Instances are frozen by default. You can change behavior by specifying whether instances should be mutable by passing `kind: :mutable` as a keyword argument. Example:
|
|
166
168
|
|
|
167
169
|
[source,ruby]
|
|
168
170
|
----
|
|
171
|
+
require "wholeable"
|
|
172
|
+
|
|
169
173
|
class Person
|
|
170
174
|
include Wholeable[:name, :email, kind: :mutable]
|
|
171
175
|
|
|
@@ -196,6 +200,8 @@ Unlike {data_link} or {structs_link}, you can subclass a whole value object. Exa
|
|
|
196
200
|
|
|
197
201
|
[source,ruby]
|
|
198
202
|
----
|
|
203
|
+
require "wholeable"
|
|
204
|
+
|
|
199
205
|
class Person
|
|
200
206
|
include Wholeable[:name]
|
|
201
207
|
|
|
@@ -229,6 +235,8 @@ If your ancestry is a mixed (immutable and mutable) then behavior is specific to
|
|
|
229
235
|
|
|
230
236
|
[source,ruby]
|
|
231
237
|
----
|
|
238
|
+
require "wholeable"
|
|
239
|
+
|
|
232
240
|
class Parent
|
|
233
241
|
include Wholeable[:one]
|
|
234
242
|
|
|
@@ -255,10 +263,12 @@ child.frozen? # false
|
|
|
255
263
|
|
|
256
264
|
Notice, when attempting to mutate the `one` attribute, you get a `NoMethodError`. This is because `#one=` is defined by the _immutable_ parent while `#two=` is defined on the _mutable_ child.
|
|
257
265
|
|
|
258
|
-
If you the flip mutability of your ancestry, you can make your parent mutable while the child immutable
|
|
266
|
+
If you the flip mutability of your ancestry, you can make your parent mutable while the child is immutable with different behavior. Example:
|
|
259
267
|
|
|
260
268
|
[source,ruby]
|
|
261
269
|
----
|
|
270
|
+
require "wholeable"
|
|
271
|
+
|
|
262
272
|
class Parent
|
|
263
273
|
include Wholeable[:one, kind: :mutable]
|
|
264
274
|
|
|
@@ -296,47 +306,59 @@ Whole values can be broken via the following situations:
|
|
|
296
306
|
|
|
297
307
|
== Performance
|
|
298
308
|
|
|
299
|
-
The performance of this gem is
|
|
309
|
+
The performance of this gem is slightly slower than native support for {data_link} and {structs_link} because they are written in C. To illustrate, here's a micro benchmark for comparison:
|
|
300
310
|
|
|
301
311
|
----
|
|
302
312
|
INITIALIZATION
|
|
303
313
|
|
|
304
|
-
ruby
|
|
314
|
+
ruby 4.0.1 (2026-01-13 revision e04267a14b) +YJIT +PRISM [arm64-darwin25.2.0]
|
|
305
315
|
Warming up --------------------------------------
|
|
306
|
-
Data
|
|
307
|
-
|
|
308
|
-
|
|
316
|
+
Data 411.580k i/100ms
|
|
317
|
+
Equalizer 2.225M i/100ms
|
|
318
|
+
Equatable 2.321M i/100ms
|
|
319
|
+
Struct 455.823k i/100ms
|
|
320
|
+
Wholeable 859.120k i/100ms
|
|
309
321
|
Calculating -------------------------------------
|
|
310
|
-
Data 4.
|
|
311
|
-
|
|
312
|
-
|
|
322
|
+
Data 4.903M (± 8.8%) i/s (203.94 ns/i) - 24.695M in 5.072786s
|
|
323
|
+
Equalizer 25.434M (± 8.5%) i/s (39.32 ns/i) - 126.805M in 5.018058s
|
|
324
|
+
Equatable 25.399M (± 7.9%) i/s (39.37 ns/i) - 127.656M in 5.053633s
|
|
325
|
+
Struct 4.811M (± 7.7%) i/s (207.85 ns/i) - 24.159M in 5.048700s
|
|
326
|
+
Wholeable 10.649M (± 8.9%) i/s (93.91 ns/i) - 53.265M in 5.044738s
|
|
313
327
|
|
|
314
328
|
Comparison:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
329
|
+
Equalizer: 25434240.3 i/s
|
|
330
|
+
Equatable: 25398808.9 i/s - same-ish: difference falls within error
|
|
331
|
+
Wholeable: 10648737.2 i/s - 2.39x slower
|
|
332
|
+
Data: 4903352.0 i/s - 5.19x slower
|
|
333
|
+
Struct: 4811046.3 i/s - 5.29x slower
|
|
318
334
|
|
|
319
|
-
|
|
335
|
+
MESSAGING
|
|
320
336
|
|
|
321
|
-
ruby
|
|
337
|
+
ruby 4.0.1 (2026-01-13 revision e04267a14b) +YJIT +PRISM [arm64-darwin25.2.0]
|
|
322
338
|
Warming up --------------------------------------
|
|
323
|
-
Data
|
|
324
|
-
|
|
325
|
-
|
|
339
|
+
Data 125.714k i/100ms
|
|
340
|
+
Equalizer 97.991k i/100ms
|
|
341
|
+
Equatable 94.801k i/100ms
|
|
342
|
+
Struct 121.077k i/100ms
|
|
343
|
+
Wholeable 96.806k i/100ms
|
|
326
344
|
Calculating -------------------------------------
|
|
327
|
-
Data 1.
|
|
328
|
-
|
|
329
|
-
|
|
345
|
+
Data 1.368M (±12.1%) i/s (731.11 ns/i) - 6.789M in 5.052046s
|
|
346
|
+
Equalizer 997.443k (±11.4%) i/s (1.00 μs/i) - 4.998M in 5.074622s
|
|
347
|
+
Equatable 996.404k (± 9.6%) i/s (1.00 μs/i) - 5.024M in 5.087767s
|
|
348
|
+
Struct 1.429M (±10.0%) i/s (699.99 ns/i) - 7.144M in 5.051871s
|
|
349
|
+
Wholeable 967.377k (±10.7%) i/s (1.03 μs/i) - 4.840M in 5.060414s
|
|
330
350
|
|
|
331
351
|
Comparison:
|
|
332
|
-
Struct:
|
|
333
|
-
Data:
|
|
334
|
-
|
|
352
|
+
Struct: 1428586.9 i/s
|
|
353
|
+
Data: 1367792.5 i/s - same-ish: difference falls within error
|
|
354
|
+
Equalizer: 997443.1 i/s - 1.43x slower
|
|
355
|
+
Equatable: 996404.3 i/s - 1.43x slower
|
|
356
|
+
Wholeable: 967377.2 i/s - 1.48x slower
|
|
335
357
|
----
|
|
336
358
|
|
|
337
|
-
While the above isn't bad, you can
|
|
359
|
+
While the above isn't bad, you can see this gem is slower than Ruby's own native objects during interaction despite being faster upon initialization.
|
|
338
360
|
|
|
339
|
-
|
|
361
|
+
Prefer using {data_link} or {structs_link} first but, if you find yourself needing a whole value object with more behavior than what a `Data` or `Struct` can provide, then this gem is a good solution.
|
|
340
362
|
|
|
341
363
|
== Development
|
|
342
364
|
|
data/wholeable.gemspec
CHANGED
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wholeable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brooke Kuhlmann
|
|
@@ -9,9 +9,9 @@ bindir: bin
|
|
|
9
9
|
cert_chain:
|
|
10
10
|
- |
|
|
11
11
|
-----BEGIN CERTIFICATE-----
|
|
12
|
-
|
|
12
|
+
MIIENjCCAp6gAwIBAgIBAzANBgkqhkiG9w0BAQsFADBBMQ8wDQYDVQQDDAZicm9v
|
|
13
13
|
a2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQBGRYC
|
|
14
|
-
|
|
14
|
+
aW8wHhcNMjYwMzI1MTI0OTEyWhcNMjcwMzI1MTI0OTEyWjBBMQ8wDQYDVQQDDAZi
|
|
15
15
|
cm9va2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1p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BIXIOkwKKJ0eB5YHrUSJxzpP4LlcIg/eTftaXmJdYjy+2VRrCZYDjfguyLmMjR
|
|
34
|
+
KR9w4/Fjvqy87kCHmxMWa6IL2Vzt1Clm2cA=
|
|
35
35
|
-----END CERTIFICATE-----
|
|
36
36
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
37
37
|
dependencies: []
|
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
74
|
version: '0'
|
|
75
75
|
requirements: []
|
|
76
|
-
rubygems_version: 4.0.
|
|
76
|
+
rubygems_version: 4.0.10
|
|
77
77
|
specification_version: 4
|
|
78
78
|
summary: Provides whole value object behavior.
|
|
79
79
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|