wholable 1.2.0 → 1.4.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 +1 -1
- 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: dd44d064969da79ee7c5656fd89b12422192c8fa23da68e6dcfcba2f2a4da87d
|
4
|
+
data.tar.gz: b3c92696abf07121f2e3ce980663f9b3a12bd4ecb82b61143f59a3c7e78f7388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a625b38d227045155cb29ad4d241a6e3e0fee4c2a17b26bd95d1f46af2a890f9a5ed0d3a16c826643cad0d29948873efe030ecb17697d78156627ffb7cf039c
|
7
|
+
data.tar.gz: f9c0d337aa9f21742b45910d7234eb8be0b43f01836c90c2181d9431068fc94749100eb6cea66d18de2265f320ef31a996d36c062c2f74537a6162ecf1657636
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -38,7 +38,7 @@ To install _with_ security, run:
|
|
38
38
|
[source,bash]
|
39
39
|
----
|
40
40
|
# 💡 Skip this line if you already have the public certificate installed.
|
41
|
-
gem cert --add <(curl --compressed --location https://alchemists.io/
|
41
|
+
gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
|
42
42
|
gem install wholable --trust-policy HighSecurity
|
43
43
|
----
|
44
44
|
|
@@ -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.4.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.4.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-
|
38
|
+
date: 2024-05-31 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.11
|
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
|