wholable 1.1.0 → 1.3.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: 8610a5c34f60d8c438651eb0ae6be5bf226636fab81ffc37f1f0c93a82a86448
4
- data.tar.gz: 7c9b5174c58c0d79605aa68010675b2a148818f26207cfdb9a7b91034e942432
3
+ metadata.gz: 1a2fc8f0bef11d35696d7862dfe9c3fbcce6879025a68c9b42741fc6664d1aae
4
+ data.tar.gz: ecbe16daf2eb524ecca434c312ca0cf34af1e38155570dcab2b436c58a0ea14e
5
5
  SHA512:
6
- metadata.gz: 3cf1d584c290ef1b59c25b554672aa8f979f08cb2a68719b2ea571dd7e967dc3200c2fb24f48f4b43491ea0f98d0ee95c7e832b83169bcf72d7342ab4d143bc5
7
- data.tar.gz: 7a4ba2384d6be6ca37e76884ac1721b953d4122f641ac0d4042d79d8ff3b0a8ddc7053a64e5847537be4933891678c5a1137e9e130c580524c67f0ecefd2318b
6
+ metadata.gz: f482b18b2bd8288f1bfbfd63e1c7fc81494f9a568f3c643246843abbafd4c633d8d4322e39d89491bdc60632e0d1592b40c0c8dbf2a562e33dd9ab0ae8ea59fe
7
+ data.tar.gz: 663a79d0adddd16784c9ed98d736cf6ecbf2a78cb104f1ee8bdac34b5a7c873a3105420d74cb49c0cd1e291d9236426b9921405b6959602481b269f6bf9b5b14
checksums.yaml.gz.sig CHANGED
Binary file
@@ -2,65 +2,51 @@
2
2
 
3
3
  module Wholable
4
4
  # Provides core equality behavior.
5
- class Equatable < Module
5
+ class Builder < Module
6
6
  def initialize *keys
7
7
  super()
8
8
  @keys = keys.uniq
9
- define_instance_methods
9
+ private_methods.grep(/\A(define)_/).sort.each { |method| __send__ method }
10
10
  freeze
11
11
  end
12
12
 
13
13
  def included descendant
14
14
  super
15
- define_class_methods descendant
16
- descendant.include Comparable
17
- descendant.prepend Freezable
18
- end
19
15
 
20
- private
16
+ descendant.class_eval <<-READER, __FILE__, __LINE__ + 1
17
+ def self.new(...) = super.freeze
21
18
 
22
- attr_reader :keys
19
+ attr_reader #{keys.map(&:inspect).join ", "}
20
+ READER
23
21
 
24
- def define_instance_methods
25
- define_hash
26
- define_inspect
27
- define_with
28
- define_to_a
29
- define_to_h
30
- define_diff
22
+ descendant.alias_method :deconstruct, :to_a
23
+ descendant.alias_method :deconstruct_keys, :to_h
31
24
  end
32
25
 
33
- def define_class_methods descendant
34
- define_readers descendant
35
- define_deconstruct descendant
36
- define_deconstruct_keys descendant
37
- end
26
+ private
38
27
 
39
- def define_readers descendant
40
- descendant.class_eval <<-READERS, __FILE__, __LINE__ + 1
41
- attr_reader #{keys.map(&:inspect).join ", "}
42
- READERS
43
- end
28
+ attr_reader :keys
44
29
 
45
- def define_deconstruct descendant
46
- descendant.class_eval <<-READERS, __FILE__, __LINE__ + 1
47
- alias deconstruct to_a
48
- READERS
30
+ def define_diff
31
+ define_method :diff do |other|
32
+ if other.is_a? self.class
33
+ to_h.merge!(other.to_h) { |_, one, two| [one, two].uniq }
34
+ .select { |_, diff| diff.size == 2 }
35
+ else
36
+ to_h.each.with_object({}) { |(key, value), diff| diff[key] = [value, nil] }
37
+ end
38
+ end
49
39
  end
50
40
 
51
- def define_deconstruct_keys descendant
52
- descendant.class_eval <<-READERS, __FILE__, __LINE__ + 1
53
- alias deconstruct_keys to_h
54
- READERS
41
+ def define_eql
42
+ define_method(:eql?) { |other| instance_of?(other.class) && hash == other.hash }
55
43
  end
56
44
 
57
- def define_with
58
- define_method(:with) { |**attributes| self.class.new(**to_h.merge!(attributes)) }
45
+ def define_equality
46
+ define_method(:==) { |other| other.is_a?(self.class) && hash == other.hash }
59
47
  end
60
48
 
61
- def define_hash
62
- local_keys = keys
63
-
49
+ def define_hash local_keys = keys
64
50
  define_method :hash do
65
51
  local_keys.map { |key| public_send key }
66
52
  .prepend(self.class)
@@ -68,9 +54,7 @@ module Wholable
68
54
  end
69
55
  end
70
56
 
71
- def define_inspect
72
- local_keys = keys
73
-
57
+ def define_inspect local_keys = keys
74
58
  define_method :inspect do
75
59
  klass = self.class
76
60
  name = klass.name || klass.inspect
@@ -81,31 +65,20 @@ module Wholable
81
65
  end
82
66
  end
83
67
 
84
- def define_to_a
85
- local_keys = keys
86
-
68
+ def define_to_a local_keys = keys
87
69
  define_method :to_a do
88
70
  local_keys.reduce([]) { |array, key| array.append public_send(key) }
89
71
  end
90
72
  end
91
73
 
92
- def define_to_h
93
- local_keys = keys
94
-
74
+ def define_to_h local_keys = keys
95
75
  define_method :to_h do
96
76
  local_keys.each.with_object({}) { |key, dictionary| dictionary[key] = public_send key }
97
77
  end
98
78
  end
99
79
 
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
80
+ def define_with
81
+ define_method(:with) { |**attributes| self.class.new(**to_h.merge!(attributes)) }
109
82
  end
110
83
  end
111
84
  end
data/lib/wholable.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "wholable/comparable"
4
- require "wholable/equatable"
5
- require "wholable/freezable"
3
+ require "wholable/builder"
6
4
 
7
5
  # Main namespace.
8
6
  module Wholable
9
- def self.[](...) = Equatable.new(...)
7
+ def self.[](*) = Builder.new(*)
10
8
  end
data/wholable.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "wholable"
5
- spec.version = "1.1.0"
5
+ spec.version = "1.3.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/wholable"
9
- spec.summary = "A whole value object mixin."
9
+ spec.summary = "A whole value object enabler."
10
10
  spec.license = "Hippocratic-2.1"
11
11
 
12
12
  spec.metadata = {
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: 1.1.0
4
+ version: 1.3.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: 2024-03-03 00:00:00.000000000 Z
38
+ date: 2024-04-30 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description:
41
41
  email:
@@ -49,9 +49,7 @@ files:
49
49
  - LICENSE.adoc
50
50
  - README.adoc
51
51
  - lib/wholable.rb
52
- - lib/wholable/comparable.rb
53
- - lib/wholable/equatable.rb
54
- - lib/wholable/freezable.rb
52
+ - lib/wholable/builder.rb
55
53
  - wholable.gemspec
56
54
  homepage: https://alchemists.io/projects/wholable
57
55
  licenses:
@@ -79,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
77
  - !ruby/object:Gem::Version
80
78
  version: '0'
81
79
  requirements: []
82
- rubygems_version: 3.5.6
80
+ rubygems_version: 3.5.9
83
81
  signing_key:
84
82
  specification_version: 4
85
- summary: A whole value object mixin.
83
+ summary: A whole value object enabler.
86
84
  test_files: []
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- n^?_ٟ9���`�����ݥ��)���'��X���M�H���Ͽ����Z�d+]N#���Q�/ɘ�҆�6[R�bel���vq:
2
- ,�<�ܒ*]�j�hU���Q�j����\� ���إR�#�*D_j��A��%�*��e9"o�:�@���yv7/GO��s�,�{�y�)Zf��X�R��G������=B{.��k�.F@��_��)�>F��:
1
+ Q�r�2/��'i a+%̹g͛SN{�8g����ֿ9Et�ڣ�h���mn��M<X\-VX��u��
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wholable
4
- # Provides object equality comparison methods.
5
- module Comparable
6
- def eql?(other) = instance_of?(other.class) && hash == other.hash
7
-
8
- def ==(other) = other.is_a?(self.class) && hash == other.hash
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wholable
4
- # Ensures an object is frozen after being initialized.
5
- module Freezable
6
- def initialize(...)
7
- super
8
- freeze
9
- end
10
- end
11
- end