dry-core 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/dry/core/memoizable.rb +45 -24
- data/lib/dry/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb330574bba6050e9a3d0fd466fdbd276ce76749b2661b8091ebf6178a2ef6c9
|
4
|
+
data.tar.gz: c1319b83600515df992a91556000989aa092d4229f69669b8f544368d93d21a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b1967bb0c991637ea01da5d267df78daa12e4801288932372eca2ecf8aff0c5933ef2cb9cdc06d978d6223da963a31dc5e362f1ad1052490e10ebbc2b39fae6
|
7
|
+
data.tar.gz: 22662f066d46742cfd12d79eddcfb1e76811ab00b0080be8bac8fef53a1229fa91f5501b9f0b34f09182f5843c7bf995332fc16d1fe192daeadff186cd543cb7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 0.7.1 2021-07-10
|
4
|
+
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- [memoizable] memoizable correctly handles cases where a method
|
9
|
+
has unnamed params (e.g. happens when the new `...` syntax is used) (@flash-gordon)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
[Compare v0.7.0...v0.7.1](https://github.com/dry-rb/dry-core/compare/v0.7.0...v0.7.1)
|
14
|
+
|
3
15
|
## 0.7.0 2021-07-08
|
4
16
|
|
5
17
|
|
@@ -11,6 +23,7 @@
|
|
11
23
|
### Changed
|
12
24
|
|
13
25
|
- Minimal Ruby version is 2.6
|
26
|
+
- [memoizable] memoization of block-accepting methods is deprecated (@flash-gordon)
|
14
27
|
|
15
28
|
[Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-core/compare/v0.6.0...v0.7.0)
|
16
29
|
|
data/lib/dry/core/memoizable.rb
CHANGED
@@ -6,6 +6,7 @@ module Dry
|
|
6
6
|
module Core
|
7
7
|
module Memoizable
|
8
8
|
MEMOIZED_HASH = {}.freeze
|
9
|
+
PARAM_PLACEHOLDERS = %i[* ** &].freeze
|
9
10
|
|
10
11
|
module ClassInterface
|
11
12
|
module Base
|
@@ -64,25 +65,26 @@ module Dry
|
|
64
65
|
private
|
65
66
|
|
66
67
|
# @api private
|
67
|
-
def define_memoizable(method:)
|
68
|
+
def define_memoizable(method:) # rubocop:disable Metrics/AbcSize
|
68
69
|
parameters = method.parameters
|
69
70
|
|
70
71
|
if parameters.empty?
|
71
72
|
key = method.name.hash
|
72
|
-
module_eval
|
73
|
-
def #{method.name}
|
74
|
-
if @__memoized__.key?(#{key})
|
75
|
-
@__memoized__[#{key}]
|
76
|
-
else
|
77
|
-
@__memoized__[#{key}] = super
|
78
|
-
end
|
79
|
-
end
|
73
|
+
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
74
|
+
def #{method.name} # def slow_fetch
|
75
|
+
if @__memoized__.key?(#{key}) # if @__memoized__.key?(12345678)
|
76
|
+
@__memoized__[#{key}] # @__memoized__[12345678]
|
77
|
+
else # else
|
78
|
+
@__memoized__[#{key}] = super # @__memoized__[12345678] = super
|
79
|
+
end # end
|
80
|
+
end # end
|
80
81
|
RUBY
|
81
82
|
else
|
82
83
|
mapping = parameters.to_h { |k, v = nil| [k, v] }
|
83
84
|
params, binds = declaration(parameters, mapping)
|
85
|
+
last_param = parameters.last
|
84
86
|
|
85
|
-
if
|
87
|
+
if last_param[0].eql?(:block) && !last_param[1].eql?(:&)
|
86
88
|
Deprecations.warn(<<~WARN)
|
87
89
|
Memoization for block-accepting methods isn't safe.
|
88
90
|
Every call creates a new block instance bloating cached results.
|
@@ -91,21 +93,23 @@ module Dry
|
|
91
93
|
WARN
|
92
94
|
end
|
93
95
|
|
94
|
-
module_eval
|
95
|
-
def #{method.name}(#{params.join(", ")})
|
96
|
-
key = [:"#{method.name}", #{binds.join(", ")}].hash
|
97
|
-
|
98
|
-
if @__memoized__.key?(key)
|
99
|
-
@__memoized__[key]
|
100
|
-
else
|
101
|
-
@__memoized__[key] = super
|
102
|
-
end
|
103
|
-
end
|
96
|
+
m = module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
97
|
+
def #{method.name}(#{params.join(", ")}) # def slow_calc(arg1, arg2, arg3)
|
98
|
+
key = [:"#{method.name}", #{binds.join(", ")}].hash # [:slow_calc, arg1, arg2, arg3].hash
|
99
|
+
#
|
100
|
+
if @__memoized__.key?(key) # if @__memoized__.key?(key)
|
101
|
+
@__memoized__[key] # @__memoized__[key]
|
102
|
+
else # else
|
103
|
+
@__memoized__[key] = super # @__memoized__[key] = super
|
104
|
+
end # end
|
105
|
+
end # end
|
104
106
|
RUBY
|
105
107
|
|
106
108
|
if respond_to?(:ruby2_keywords, true) && mapping.key?(:reyrest)
|
107
109
|
ruby2_keywords(method.name)
|
108
110
|
end
|
111
|
+
|
112
|
+
m
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
@@ -116,13 +120,13 @@ module Dry
|
|
116
120
|
defined = {}
|
117
121
|
|
118
122
|
definition.each do |type, name|
|
119
|
-
mapped_type = map_bind_type(type, lookup, defined) do
|
123
|
+
mapped_type = map_bind_type(type, name, lookup, defined) do
|
120
124
|
raise ::NotImplementedError, "type: #{type}, name: #{name}"
|
121
125
|
end
|
122
126
|
|
123
127
|
if mapped_type
|
124
128
|
defined[mapped_type] = true
|
125
|
-
bind = name || make_bind_name(binds.size)
|
129
|
+
bind = name_from_param(name) || make_bind_name(binds.size)
|
126
130
|
|
127
131
|
binds << bind
|
128
132
|
params << param(bind, mapped_type)
|
@@ -132,18 +136,35 @@ module Dry
|
|
132
136
|
[params, binds]
|
133
137
|
end
|
134
138
|
|
139
|
+
# @api private
|
140
|
+
def name_from_param(name)
|
141
|
+
if PARAM_PLACEHOLDERS.include?(name)
|
142
|
+
nil
|
143
|
+
else
|
144
|
+
name
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
135
148
|
# @api private
|
136
149
|
def make_bind_name(idx)
|
137
150
|
:"__lv_#{idx}__"
|
138
151
|
end
|
139
152
|
|
140
153
|
# @api private
|
141
|
-
def map_bind_type(type, original_params, defined_types) # rubocop:disable Metrics/PerceivedComplexity
|
154
|
+
def map_bind_type(type, name, original_params, defined_types) # rubocop:disable Metrics/PerceivedComplexity
|
142
155
|
case type
|
143
156
|
when :req
|
144
157
|
:reqular
|
145
|
-
when :rest, :keyreq, :keyrest
|
158
|
+
when :rest, :keyreq, :keyrest
|
146
159
|
type
|
160
|
+
when :block
|
161
|
+
if name.eql?(:&)
|
162
|
+
# most likely this is a case of delegation
|
163
|
+
# rather than actual block
|
164
|
+
nil
|
165
|
+
else
|
166
|
+
type
|
167
|
+
end
|
147
168
|
when :opt
|
148
169
|
if original_params.key?(:rest) || defined_types[:rest]
|
149
170
|
nil
|
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|