dry-core 0.4.10 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/dry-core.rb +1 -1
- data/lib/dry/core.rb +1 -1
- data/lib/dry/core/cache.rb +1 -1
- data/lib/dry/core/class_attributes.rb +2 -2
- data/lib/dry/core/constants.rb +4 -4
- data/lib/dry/core/deprecations.rb +1 -1
- data/lib/dry/core/descendants_tracker.rb +1 -1
- data/lib/dry/core/equalizer.rb +151 -0
- data/lib/dry/core/extensions.rb +1 -1
- data/lib/dry/core/inflector.rb +5 -5
- data/lib/dry/core/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 455db6bceb946acab5dbe431c4ba7edf9a7344f09c2b2af9e38c0b8788e3d600
|
4
|
+
data.tar.gz: c460402f0b99fbe8ad488463cebd828a6a814d0a45f5200fbf1c90302fa66649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c07482895edfb498acc414cc6672c2fa271cbd892f59393b4baa6b3b7ec4e115b29474be85fe42e40660fe06f926442608d693816594bdfcd910411185acad9c
|
7
|
+
data.tar.gz: c3d0966d660f09a26007e226b57e1cc2c124a420606b4de5d104730c6f5d9c54492a89788fb601722eab10f42dac4cda5d6689c79fe6c53a3df9c6510569fa7e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## unreleased
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- dry-equalizer has been imported into dry-core as `Dry::Core::Equalizer` but the interface remains the same, which is `include Dry.Equalizer(...)` - we'll be porting all other gems that depend on dry-equalizer to the latest dry-core with equalizer included *gradually*. Eventually dry-equalizer usage will be gone completely in rom-rb/dry-rb/hanami projects (@solnic)
|
9
|
+
|
10
|
+
|
11
|
+
[Compare v0.4.10...master](https://github.com/dry-rb/dry-core/compare/v0.4.10...master)
|
12
|
+
|
1
13
|
## 0.4.10 2020-11-19
|
2
14
|
|
3
15
|
|
data/lib/dry-core.rb
CHANGED
data/lib/dry/core.rb
CHANGED
data/lib/dry/core/cache.rb
CHANGED
data/lib/dry/core/constants.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "set"
|
4
4
|
|
5
5
|
module Dry
|
6
6
|
module Core
|
@@ -25,7 +25,7 @@ module Dry
|
|
25
25
|
# An empty set
|
26
26
|
EMPTY_SET = ::Set.new.freeze
|
27
27
|
# An empty string
|
28
|
-
EMPTY_STRING =
|
28
|
+
EMPTY_STRING = "".freeze
|
29
29
|
# Identity function
|
30
30
|
IDENTITY = (-> x { x }).freeze
|
31
31
|
|
@@ -46,12 +46,12 @@ module Dry
|
|
46
46
|
|
47
47
|
# @api public
|
48
48
|
def undefined.to_s
|
49
|
-
|
49
|
+
"Undefined"
|
50
50
|
end
|
51
51
|
|
52
52
|
# @api public
|
53
53
|
def undefined.inspect
|
54
|
-
|
54
|
+
"Undefined"
|
55
55
|
end
|
56
56
|
|
57
57
|
# Pick a value, if the first argument is not Undefined, return it back,
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
# Build an equalizer module for the inclusion in other class
|
5
|
+
#
|
6
|
+
# ## Credits
|
7
|
+
#
|
8
|
+
# Equalizer has been originally imported from the equalizer gem created by Dan Kubb
|
9
|
+
#
|
10
|
+
# @api public
|
11
|
+
def self.Equalizer(*keys, **options)
|
12
|
+
Dry::Core::Equalizer.new(*keys, **options)
|
13
|
+
end
|
14
|
+
|
15
|
+
module Core
|
16
|
+
# Define equality, equivalence and inspection methods
|
17
|
+
class Equalizer < Module
|
18
|
+
# Initialize an Equalizer with the given keys
|
19
|
+
#
|
20
|
+
# Will use the keys with which it is initialized to define #cmp?,
|
21
|
+
# #hash, and #inspect
|
22
|
+
#
|
23
|
+
# @param [Array<Symbol>] keys
|
24
|
+
# @param [Hash] options
|
25
|
+
# @option options [Boolean] :inspect whether to define #inspect method
|
26
|
+
# @option options [Boolean] :immutable whether to memoize #hash method
|
27
|
+
#
|
28
|
+
# @return [undefined]
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
def initialize(*keys, **options)
|
32
|
+
@keys = keys.uniq
|
33
|
+
define_methods(**options)
|
34
|
+
freeze
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# Hook called when module is included
|
40
|
+
#
|
41
|
+
# @param [Module] descendant
|
42
|
+
# the module or class including Equalizer
|
43
|
+
#
|
44
|
+
# @return [self]
|
45
|
+
#
|
46
|
+
# @api private
|
47
|
+
def included(descendant)
|
48
|
+
super
|
49
|
+
descendant.include Methods
|
50
|
+
end
|
51
|
+
|
52
|
+
# Define the equalizer methods based on #keys
|
53
|
+
#
|
54
|
+
# @param [Boolean] inspect whether to define #inspect method
|
55
|
+
# @param [Boolean] immutable whether to memoize #hash method
|
56
|
+
#
|
57
|
+
# @return [undefined]
|
58
|
+
#
|
59
|
+
# @api private
|
60
|
+
def define_methods(inspect: true, immutable: false)
|
61
|
+
define_cmp_method
|
62
|
+
define_hash_method(immutable: immutable)
|
63
|
+
define_inspect_method if inspect
|
64
|
+
end
|
65
|
+
|
66
|
+
# Define an #cmp? method based on the instance's values identified by #keys
|
67
|
+
#
|
68
|
+
# @return [undefined]
|
69
|
+
#
|
70
|
+
# @api private
|
71
|
+
def define_cmp_method
|
72
|
+
keys = @keys
|
73
|
+
define_method(:cmp?) do |comparator, other|
|
74
|
+
keys.all? do |key|
|
75
|
+
__send__(key).public_send(comparator, other.__send__(key))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
private :cmp?
|
79
|
+
end
|
80
|
+
|
81
|
+
# Define a #hash method based on the instance's values identified by #keys
|
82
|
+
#
|
83
|
+
# @return [undefined]
|
84
|
+
#
|
85
|
+
# @api private
|
86
|
+
def define_hash_method(immutable:)
|
87
|
+
calculate_hash = ->(obj) { @keys.map { |key| obj.__send__(key) }.push(obj.class).hash }
|
88
|
+
if immutable
|
89
|
+
define_method(:hash) do
|
90
|
+
@__hash__ ||= calculate_hash.call(self)
|
91
|
+
end
|
92
|
+
define_method(:freeze) do
|
93
|
+
hash
|
94
|
+
super()
|
95
|
+
end
|
96
|
+
else
|
97
|
+
define_method(:hash) do
|
98
|
+
calculate_hash.call(self)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Define an inspect method that reports the values of the instance's keys
|
104
|
+
#
|
105
|
+
# @return [undefined]
|
106
|
+
#
|
107
|
+
# @api private
|
108
|
+
def define_inspect_method
|
109
|
+
keys = @keys
|
110
|
+
define_method(:inspect) do
|
111
|
+
klass = self.class
|
112
|
+
name = klass.name || klass.inspect
|
113
|
+
"#<#{name}#{keys.map { |key| " #{key}=#{__send__(key).inspect}" }.join}>"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# The comparison methods
|
118
|
+
module Methods
|
119
|
+
# Compare the object with other object for equality
|
120
|
+
#
|
121
|
+
# @example
|
122
|
+
# object.eql?(other) # => true or false
|
123
|
+
#
|
124
|
+
# @param [Object] other
|
125
|
+
# the other object to compare with
|
126
|
+
#
|
127
|
+
# @return [Boolean]
|
128
|
+
#
|
129
|
+
# @api public
|
130
|
+
def eql?(other)
|
131
|
+
instance_of?(other.class) && cmp?(__method__, other)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Compare the object with other object for equivalency
|
135
|
+
#
|
136
|
+
# @example
|
137
|
+
# object == other # => true or false
|
138
|
+
#
|
139
|
+
# @param [Object] other
|
140
|
+
# the other object to compare with
|
141
|
+
#
|
142
|
+
# @return [Boolean]
|
143
|
+
#
|
144
|
+
# @api public
|
145
|
+
def ==(other)
|
146
|
+
other.is_a?(self.class) && cmp?(__method__, other)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/lib/dry/core/extensions.rb
CHANGED
data/lib/dry/core/inflector.rb
CHANGED
@@ -7,15 +7,15 @@ module Dry
|
|
7
7
|
# List of supported backends
|
8
8
|
BACKENDS = {
|
9
9
|
activesupport: [
|
10
|
-
|
10
|
+
"active_support/inflector",
|
11
11
|
proc { ::ActiveSupport::Inflector }
|
12
12
|
],
|
13
13
|
dry_inflector: [
|
14
|
-
|
14
|
+
"dry/inflector",
|
15
15
|
proc { Dry::Inflector.new }
|
16
16
|
],
|
17
17
|
inflecto: [
|
18
|
-
|
18
|
+
"inflecto",
|
19
19
|
proc { ::Inflecto }
|
20
20
|
]
|
21
21
|
}.freeze
|
@@ -38,8 +38,8 @@ module Dry
|
|
38
38
|
BACKENDS.inject(nil) do |backend, (_, (path, factory))|
|
39
39
|
backend || realize_backend(path, factory)
|
40
40
|
end || raise(LoadError,
|
41
|
-
|
42
|
-
|
41
|
+
"No inflector library could be found: "\
|
42
|
+
"please install either the `inflecto` or `activesupport` gem.")
|
43
43
|
end
|
44
44
|
|
45
45
|
# Set preferred backend
|
data/lib/dry/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/dry/core/constants.rb
|
86
86
|
- lib/dry/core/deprecations.rb
|
87
87
|
- lib/dry/core/descendants_tracker.rb
|
88
|
+
- lib/dry/core/equalizer.rb
|
88
89
|
- lib/dry/core/errors.rb
|
89
90
|
- lib/dry/core/extensions.rb
|
90
91
|
- lib/dry/core/inflector.rb
|