wholable 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +2 -2
- data/lib/wholable/comparable.rb +0 -9
- data/lib/wholable/equatable.rb +12 -0
- data/wholable.gemspec +1 -1
- data.tar.gz.sig +1 -4
- metadata +2 -2
- 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: 126369e88f3d51122002ebcd4de0cff80f95ad961fc0cd57f1f49e67419f7df7
|
4
|
+
data.tar.gz: c237212bd075a6d6ee075367664a9161e82dd483db94c6d69aeb2f6b65fa9283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439990b25f13e9a144b5e3c1e8487ce78bd43ee7dfe44c1ee35018ad4c13dc242ec633b1fb786c37ad95dd96b439ca0508fff502c764f1ae4c88b4550053252c
|
7
|
+
data.tar.gz: 17d4ddbcdfcaef66aefed5c2e5018cbb34b6c4efd4c7953b026d0d7ed3b2d03bb7aa04a33f620f6222fe9b735329af027c2dab5ef47dae1eacccb6f84ae97381
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -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
|
134
|
-
.
|
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
|
data/lib/wholable/comparable.rb
CHANGED
@@ -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
|
data/lib/wholable/equatable.rb
CHANGED
@@ -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
data.tar.gz.sig
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
|
2
|
-
���IR���/��A��
|
3
|
-
G�ͭ36Ғ[���6͋��VF��.�Q~W��% ����G�Y�fh��Li+���u&�b|6$�JYx�)a�v���A��_j��Ӭ"Ey��8a�Lў+��|K��/��(#u$B�� �u�Z~�p�&
|
4
|
-
C3���B�~�2��0���s�,FC��~�
|
1
|
+
��v\�����C�M���G�3V�_$p:�@/�_8a���Bp���4����H�����X����q���:�D�70�YM��x�����G�
|
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.
|
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-
|
38
|
+
date: 2023-11-04 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description:
|
41
41
|
email:
|
metadata.gz.sig
CHANGED
Binary file
|