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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bebc041fb4b4179274ef429212f91054377d05b6d4e6f353eb515a008794bff
4
- data.tar.gz: 58401fbebb0f25c9990d5f3f7a5dad7e5bc0512c1aa2787732e7c35016d913f8
3
+ metadata.gz: cb330574bba6050e9a3d0fd466fdbd276ce76749b2661b8091ebf6178a2ef6c9
4
+ data.tar.gz: c1319b83600515df992a91556000989aa092d4229f69669b8f544368d93d21a8
5
5
  SHA512:
6
- metadata.gz: da17cd2eecc9cfdc1ac6210161b94cbf46a5e572a563ab4e1173fed488ad2690fedee3c64dcb8db55285dfc3277b988de794800d21a23161b8f537c14ec6ceff
7
- data.tar.gz: 9a7530f8bdc1e5398638562a00021d689da2de8c52b704d4dc59817f0a70ce640b1e0fcc618690ff59853e437adc8456e3d8a4830978f2b0217c8bbe845bd352
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
 
@@ -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 <<~RUBY, __FILE__, __LINE__ + 1
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 parameters.last[0].eql?(:block)
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 <<~RUBY, __FILE__, __LINE__ + 1
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, :block
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Core
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.1"
6
6
  end
7
7
  end
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.0
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-08 00:00:00.000000000 Z
11
+ date: 2021-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby