wholable 0.1.0 → 0.2.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: bdd21036f1cae41b84f1db0c85aa8806770de6317ffff2e5928faa938871e9d5
4
- data.tar.gz: 258dd2e251c8dd9d385d4331c20ab6395c8ccb93c5ee47cd079849df80bf2cd2
3
+ metadata.gz: 126369e88f3d51122002ebcd4de0cff80f95ad961fc0cd57f1f49e67419f7df7
4
+ data.tar.gz: c237212bd075a6d6ee075367664a9161e82dd483db94c6d69aeb2f6b65fa9283
5
5
  SHA512:
6
- metadata.gz: add335b9cdfc0ff14334b77aff7ee3295419fcf0fe4b78470925f6f395a85ded7cd47496213e9f36695e60833b4cf04692e9c030c02869d2fbff42352cabaa36
7
- data.tar.gz: e2a9f041d020e166111905e76396887e9aae3f6f1f7475790a5dcb32678eb038c171a7e790ba1b196c0d9604463e6072e5975151980c3e67d61e930959a0a60f
6
+ metadata.gz: 439990b25f13e9a144b5e3c1e8487ce78bd43ee7dfe44c1ee35018ad4c13dc242ec633b1fb786c37ad95dd96b439ca0508fff502c764f1ae4c88b4550053252c
7
+ data.tar.gz: 17d4ddbcdfcaef66aefed5c2e5018cbb34b6c4efd4c7953b026d0d7ed3b2d03bb7aa04a33f620f6222fe9b735329af027c2dab5ef47dae1eacccb6f84ae97381
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  = Wholable
12
12
 
13
- 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]:
13
+ Wholable 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]:
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
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://rubyapi.org/o/basicobject#method-i-3D-3D[BasicObject] documentation.
@@ -130,8 +130,8 @@ As you can see, object equality is determined by the object's values and _not_ b
130
130
 
131
131
  . The corresponding _public_ `attr_reader` for each key is created which saves you time and reduces double entry when implementing your whole value object.
132
132
  . The `#to_a` and `#to_h` methods are added for convenience in order to play nice with {data_link} and {structs_link}.
133
- . The `#deconstruct` and `#deconstruct_keys` aliases are created for you so you can leverage {pattern_matching_link}.
134
- . Custom `#==`, `#eql?`, `#hash`, `#inspect`, `#to_a`, `#to_h`, and `#with` methods are added to provide whole value behavior.
133
+ . The `#deconstruct` and `#deconstruct_keys` aliases are created so you can leverage {pattern_matching_link}.
134
+ . The `#==`, `#eql?`, `#hash`, `#inspect`, and `#with` methods are added to provide whole value behavior.
135
135
  . The object is immediately frozen after initialization to ensure your instance is _immutable_ by default.
136
136
 
137
137
  == Caveats
@@ -142,15 +142,6 @@ Whole values can be broken via the following:
142
142
  * *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`, `#inspect`, `#to_a`, and `#to_h` behavior at which point you don't need Wholable anymore.
143
143
  * *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.
144
144
 
145
- == Influences
146
-
147
- This implementation is based upon these original designs:
148
-
149
- - link:https://github.com/dkubb/equalizer[Equalizer]: One of the first implementations that is over a decade old and no longer maintained.
150
- - 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.
151
- - 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.
152
- - 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.
153
-
154
145
  == Development
155
146
 
156
147
  To contribute, run:
@@ -6,14 +6,5 @@ module Wholable
6
6
  def eql?(other) = instance_of?(other.class) && hash == other.hash
7
7
 
8
8
  def ==(other) = other.is_a?(self.class) && hash == other.hash
9
-
10
- def diff other
11
- if other.is_a? self.class
12
- to_h.merge(other.to_h) { |_, one, two| [one, two].uniq }
13
- .select { |_, diff| diff.size == 2 }
14
- else
15
- to_h.each.with_object({}) { |(key, value), diff| diff[key] = [value, nil] }
16
- end
17
- end
18
9
  end
19
10
  end
@@ -27,6 +27,7 @@ module Wholable
27
27
  define_with
28
28
  define_to_a
29
29
  define_to_h
30
+ define_diff
30
31
  end
31
32
 
32
33
  def define_class_methods descendant
@@ -95,5 +96,16 @@ module Wholable
95
96
  local_keys.each.with_object({}) { |key, dictionary| dictionary[key] = public_send key }
96
97
  end
97
98
  end
99
+
100
+ def define_diff
101
+ define_method :diff do |other|
102
+ if other.is_a? self.class
103
+ to_h.merge!(other.to_h) { |_, one, two| [one, two].uniq }
104
+ .select { |_, diff| diff.size == 2 }
105
+ else
106
+ to_h.each.with_object({}) { |(key, value), diff| diff[key] = [value, nil] }
107
+ end
108
+ end
109
+ end
98
110
  end
99
111
  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.1.0"
5
+ spec.version = "0.2.0"
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.1.0
4
+ version: 0.2.0
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-08-15 00:00:00.000000000 Z
38
+ date: 2023-11-04 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.18
82
+ rubygems_version: 3.4.21
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: A whole value object mixin.
metadata.gz.sig CHANGED
Binary file