wholable 1.2.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: f540eaa42465e5e3748ea429e05e2d6dd58cdfa8494449278171431f4cc0988e
4
- data.tar.gz: 267f834158a1368a7c716de371d24137b99508b6b13c2ca87d741cee111bcfc0
3
+ metadata.gz: 1a2fc8f0bef11d35696d7862dfe9c3fbcce6879025a68c9b42741fc6664d1aae
4
+ data.tar.gz: ecbe16daf2eb524ecca434c312ca0cf34af1e38155570dcab2b436c58a0ea14e
5
5
  SHA512:
6
- metadata.gz: 9367c1662e745c179f3ecc56e1960de2d5fd35a87535e954ae219ec04e6296ed374867024e6b091becf0724a50926d6c48b6e58e2d3fc0d5a569ff376e0678ab
7
- data.tar.gz: ecfc4e395a5cd611b17e8e82540c1f0caf996a9105ce4f21099e915ea526063f1c8b42ff9661f2bb8a0642a583b3e04c167555dda21c8c1632aa15b9c6e3a104
6
+ metadata.gz: f482b18b2bd8288f1bfbfd63e1c7fc81494f9a568f3c643246843abbafd4c633d8d4322e39d89491bdc60632e0d1592b40c0c8dbf2a562e33dd9ab0ae8ea59fe
7
+ data.tar.gz: 663a79d0adddd16784c9ed98d736cf6ecbf2a78cb104f1ee8bdac34b5a7c873a3105420d74cb49c0cd1e291d9236426b9921405b6959602481b269f6bf9b5b14
checksums.yaml.gz.sig CHANGED
Binary file
@@ -2,45 +2,48 @@
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
15
+
16
+ descendant.class_eval <<-READER, __FILE__, __LINE__ + 1
17
+ def self.new(...) = super.freeze
18
+
19
+ attr_reader #{keys.map(&:inspect).join ", "}
20
+ READER
21
+
22
+ descendant.alias_method :deconstruct, :to_a
23
+ descendant.alias_method :deconstruct_keys, :to_h
18
24
  end
19
25
 
20
26
  private
21
27
 
22
28
  attr_reader :keys
23
29
 
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
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
31
39
  end
32
40
 
33
- def define_class_methods descendant
34
- descendant.class_eval <<-READER, __FILE__, __LINE__ + 1
35
- attr_reader #{keys.map(&:inspect).join ", "}
36
- READER
37
-
38
- descendant.alias_method :deconstruct, :to_a
39
- descendant.alias_method :deconstruct_keys, :to_h
41
+ def define_eql
42
+ define_method(:eql?) { |other| instance_of?(other.class) && hash == other.hash }
40
43
  end
41
44
 
42
- def define_with
43
- 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 }
44
47
  end
45
48
 
46
49
  def define_hash local_keys = keys
@@ -74,15 +77,8 @@ module Wholable
74
77
  end
75
78
  end
76
79
 
77
- def define_diff
78
- define_method :diff do |other|
79
- if other.is_a? self.class
80
- to_h.merge!(other.to_h) { |_, one, two| [one, two].uniq }
81
- .select { |_, diff| diff.size == 2 }
82
- else
83
- to_h.each.with_object({}) { |(key, value), diff| diff[key] = [value, nil] }
84
- end
85
- end
80
+ def define_with
81
+ define_method(:with) { |**attributes| self.class.new(**to_h.merge!(attributes)) }
86
82
  end
87
83
  end
88
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.2.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.2.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-04-01 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.7
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
Binary file
@@ -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