wholable 0.0.0 → 0.0.1

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: 42f00bcfb8063a21a4fb8f6427424078be9ce45365d2b41f5a6c053133b059d7
4
- data.tar.gz: 267014e8011488d2b9e3db0fcdecebe6a70c0032e8f47ea60cb0d3b035174719
3
+ metadata.gz: 926e2edcbc46f6bc80713ffcabfbcfcc7e0863ecfca039bb43aae8d79aca7727
4
+ data.tar.gz: 1b3bee9c9eeaaf4f3e3addcde40f1e49912533cb50ca0f7348bc988050da75f3
5
5
  SHA512:
6
- metadata.gz: 94334fe408aa2e6ac16589688f1c3e3a4d746f738ef9ec4c75d2031e10898463ce63954e0c8f147167396a0a18da79d312a75a5a3ce52bc663a773be824841d9
7
- data.tar.gz: b921837f4c80fb2651cf6a135c367c0fd2bbf18a5dfa47c0ad52838ad6f6482b90492e18d312093660f2f4ee693f56c49768647b50c8f7e0b5c93d0a9d99c9d7
6
+ metadata.gz: 46e3d952fed95ffc62afc158c93c802e38445b1bea62c8ff80c0edc28c4b699435bd41081d48a047d93e84d746e3a094596f58055e0207bdfdf8cfaf9292452f
7
+ data.tar.gz: 9baf38439f8ad831639f29ce8722bcda20b941a14b78330917c3efd6b1a33c713001562cbf5cc3643025fb4a5305d4b3742fe9444b57fa34a779d65b9d546dca
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -3,10 +3,16 @@
3
3
  :figure-caption!:
4
4
 
5
5
  :data_link: link:https://alchemists.io/articles/ruby_data[Data]
6
+ :ruby_link: link:https://www.ruby-lang.org[Ruby]
7
+ :structs_link: link:https://alchemists.io/articles/ruby_structs[Structs]
6
8
 
7
9
  = Wholable
8
10
 
9
- Wholable is a mixin that turns a class into a _whole value object_ by ensuring object equality is determined by the values that make up the object instead of by identity within memory.
11
+ Wholable is a mixin that 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 by identity. Whole value objects -- or value objects in general -- have the following traits as also noted via link:https://en.wikipedia.org/wiki/Value_object[Wikipedia]:
12
+
13
+ * 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}.
14
+ * 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://rubyapi.org/o/basicobject#method-i-3D-3D[BasicObject] documentation.
15
+ * 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.
10
16
 
11
17
  toc::[]
12
18
 
@@ -19,7 +25,7 @@ toc::[]
19
25
 
20
26
  == Requirements
21
27
 
22
- . link:https://www.ruby-lang.org[Ruby].
28
+ . {ruby_link}.
23
29
 
24
30
  == Setup
25
31
 
@@ -72,6 +78,9 @@ jill = Person.new name: "Jill Smith", email: "jill@example.com"
72
78
  jill_two = Person.new name: "Jill Smith", email: "jill@example.com"
73
79
  jack = Person.new name: "Jack Smith", email: "jack@example.com"
74
80
 
81
+ jill.name # "Jill Smith"
82
+ jill.email # "jill@example.com"
83
+
75
84
  jill.frozen? # true
76
85
  jill_two.frozen? # true
77
86
  jack.frozen? # true
@@ -80,9 +89,6 @@ jill.inspect # "#<Person @name=\"Jill Smith\", @email=\"jill@example.co
80
89
  jill_two.inspect # "#<Person @name=\"Jill Smith\", @email=\"jill@example.com\">"
81
90
  jack.inspect # "#<Person @name=\"Jack Smith\", @email=\"jack@example.com\">"
82
91
 
83
- jill.name # "Jill Smith"
84
- jill.email # "jill@example.com"
85
-
86
92
  jill == jill # true
87
93
  jill == jill_two # true
88
94
  jill == jack # false
@@ -100,17 +106,18 @@ jill_two.hash # 3650965837788801745
100
106
  jack.hash # 4460658980509842640
101
107
  ----
102
108
 
103
- As you can see, object equality is determined by the object's values and not by the object's identity. When you include `Wholable` along with a list of keys, the following happens:
109
+ As you can see, object equality is determined by the object's values and _not_ by the object's identity. When you include `Wholable` along with a list of keys, the following happens:
104
110
 
105
- . The corresponding _public_ `attr_reader` for each key will be created which saves you time and reduces double entry.
106
- . The object will be immediately frozen after initialization to ensure your instance is _immutable_ by default.
111
+ . The corresponding _public_ `attr_reader` for each key is created which saves you time and reduces double entry.
112
+ . Custom `#==`, `#eql?`, `#hash`, and `#inspect` methods are added to provide whole value behavior.
113
+ . The object is immediately frozen after initialization to ensure your instance is _immutable_ by default.
107
114
 
108
115
  == Caveats
109
116
 
110
- The whole value contract created for you when using this gem can be broken by doing the following:
117
+ Whole values can be broken via the following:
111
118
 
112
- * *Duplication*: Sending the `#dub` message will cause your whole value object to be unfrozen. This might be desired in certain situations but make sure to refreeze when able.
113
- * *Post Attributes*: Adding additional attributes after what is defined when including `Wholable` will break your whole value object contract so ensure you let Wholable manage this for you.
119
+ * *Duplication*: Sending the `#dup` message will cause your whole value object to be unfrozen. This might be desired in certain situations but make sure to refreeze when able.
120
+ * *Post Attributes*: Adding additional attributes after what is defined when including `Wholable` will break your whole value object. To prevent this, let Wholable manage this for you (easiest). Otherwise (harder), you can manually override `#==`, `#eql?`, `#hash`, and `#inspect` behavior at which point you probably don't need Wholable anymore.
114
121
  * *Deep Freezing*: The automatic freezing of your instances is shallow and will not deeply freeze nested attributes. This behavior mimics the behavior of {data_link} objects.
115
122
 
116
123
  == Influences
@@ -118,8 +125,9 @@ The whole value contract created for you when using this gem can be broken by do
118
125
  This implementation is based upon these original designs:
119
126
 
120
127
  - link:https://github.com/dkubb/equalizer[Equalizer]: One of the first implementations that is over a decade old and no longer maintained.
121
- - link:https://github.com/dry-rb/dry-equalizer[Dry Equalizer]: Deprecated and no longer maintained but was based upon the above implementation. A version of this has moved into link:https://dry-rb.org/gems/dry-core[Dry Core] but doesn't appear to work properly or be well supported. Even the documentation is not fully linked on the main page.
122
- - link:https://github.com/piotrmurach/equatable/tree/master[Equatable]: A similar implementation to the above but is based off what you define via your `.attr_reader`. The project hasn't been maintained or updated in several years now.
128
+ - link:https://github.com/dry-rb/dry-equalizer[Dry Equalizer]: Deprecated and no longer maintained but was based upon the above implementation and has now moved into Dry Core.
129
+ - link:https://dry-rb.org/gems/dry-core[Dry Core]: Includes the link:https://dry-rb.org/gems/dry-core/equalizer[Dry::Core::Equalizer] module which is officially supported and actively maintained by the Dry RB team. A good alternative to this gem.
130
+ - link:https://github.com/piotrmurach/equatable/tree/master[Equatable]: A similar implementation to the above but is based off what you define via your `.attr_reader`. The project hasn't been maintained or updated in several years.
123
131
 
124
132
  == Development
125
133
 
@@ -38,7 +38,6 @@ module Wholable
38
38
  end
39
39
  end
40
40
 
41
- # :reek:TooManyStatements
42
41
  def define_inspect
43
42
  local_keys = keys
44
43
 
@@ -46,7 +45,7 @@ module Wholable
46
45
  klass = self.class
47
46
  name = klass.name || klass.inspect
48
47
 
49
- local_keys.map { |key| %(@#{key}=#{public_send(key).inspect}) }
48
+ local_keys.map { |key| "@#{key}=#{public_send(key).inspect}" }
50
49
  .join(", ")
51
50
  .then { |pairs| "#<#{name} #{pairs}>" }
52
51
  end
@@ -4,7 +4,7 @@ module Wholable
4
4
  # Ensures an object is frozen after being initialized.
5
5
  module Freezable
6
6
  def initialize(...)
7
- super(...)
7
+ super
8
8
  freeze
9
9
  end
10
10
  end
data/wholable.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "wholable"
5
- spec.version = "0.0.0"
5
+ spec.version = "0.0.1"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/wholable"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wholable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-07-27 00:00:00.000000000 Z
38
+ date: 2023-08-06 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description:
41
41
  email:
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.4.17
82
+ rubygems_version: 3.4.18
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: A whole value object mixin.
metadata.gz.sig CHANGED
Binary file