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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/wholable/{equatable.rb → builder.rb} +26 -30
- data/lib/wholable.rb +2 -4
- data/wholable.gemspec +2 -2
- data.tar.gz.sig +0 -0
- metadata +5 -7
- metadata.gz.sig +0 -0
- data/lib/wholable/comparable.rb +0 -10
- data/lib/wholable/freezable.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a2fc8f0bef11d35696d7862dfe9c3fbcce6879025a68c9b42741fc6664d1aae
|
4
|
+
data.tar.gz: ecbe16daf2eb524ecca434c312ca0cf34af1e38155570dcab2b436c58a0ea14e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
5
|
+
class Builder < Module
|
6
6
|
def initialize *keys
|
7
7
|
super()
|
8
8
|
@keys = keys.uniq
|
9
|
-
|
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
|
-
|
16
|
-
descendant.
|
17
|
-
|
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
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
34
|
-
|
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
|
43
|
-
define_method(
|
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
|
78
|
-
define_method
|
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/
|
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.[](
|
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.
|
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
|
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.
|
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-
|
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/
|
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.
|
80
|
+
rubygems_version: 3.5.9
|
83
81
|
signing_key:
|
84
82
|
specification_version: 4
|
85
|
-
summary: A whole value object
|
83
|
+
summary: A whole value object enabler.
|
86
84
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/wholable/comparable.rb
DELETED
@@ -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
|