dry-schema 1.0.1 → 1.0.2

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: c66e7f3b66548c71cfc384f907b92c20d5328c1e726557d8a2a5084605818d7b
4
- data.tar.gz: 4e0737dc66accd0149367edb1e2494f2cf776859023ced9eee36b7b6c2962804
3
+ metadata.gz: 1bf48198c497de44b2a8511ef4ba4189ea9cb94a7eeef95dfd816702e867636b
4
+ data.tar.gz: 2189a1c1c034de218601a2cafeff4fe0d4d1a5b5162b9ceed116ec0cd0989b2a
5
5
  SHA512:
6
- metadata.gz: 7b2203dd173361640beba6981c4dafc16a11ec5bb31429cf5457f8447622648969b07a0f7b5eb1bd2c7fbd74fe2667a8bc1bb7f3564f71fb048d3fe4f35dce74
7
- data.tar.gz: a657196a6d00386336654dd75a79142674d36fb101ae45796ebc9afd75467e31470e86862f7fa1cf759d4a406dd79b0cca0a09c587befd6ac81f766c78322f27
6
+ metadata.gz: d56209a51e4f48ceb29e6c9f7302d7ba184c13f1db0163d05754a95b7c3e7642e47cdb5cf89989dbc419747a48d4623b4906c7dd532700e6980a02420a361bbe
7
+ data.tar.gz: df81a0c7769187c928923de9750e1111b0acf8bc8324a1a6f50bffa3a4bf9c2c2edceb78c2de3d69d7962778450ba1f4745d79d979df46a9e4b3daaf388f51e0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v1.0.2 2019-05-12
2
+
3
+ ### Fixed
4
+
5
+ * Caching message templates uses restricted set of known keys to calculate cache keys (issue #132) (solnic)
6
+
7
+ [Compare v1.0.1...v1.0.2](https://github.com/dry-rb/dry-schema/compare/v1.0.1...v1.0.2)
8
+
1
9
  # 1.0.1 2019-05-08
2
10
 
3
11
  ### Fixed
@@ -45,6 +45,8 @@ module Dry
45
45
  String => 'string'
46
46
  )
47
47
 
48
+ CACHE_KEYS = %i[path message_type val_type arg_type locale].freeze
49
+
48
50
  # @api private
49
51
  def self.cache
50
52
  @cache ||= Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new }
@@ -71,11 +73,6 @@ module Dry
71
73
  messages.prepare
72
74
  end
73
75
 
74
- # @api private
75
- def hash
76
- @hash ||= config.hash
77
- end
78
-
79
76
  # @api private
80
77
  def translate(key, locale: default_locale)
81
78
  t["#{config.top_namespace}.#{key}", locale: locale]
@@ -95,14 +92,24 @@ module Dry
95
92
  # @return [Template]
96
93
  #
97
94
  # @api public
98
- def call(*args)
99
- cache.fetch_or_store(args.hash) do
100
- text, meta = lookup(*args)
95
+ def call(predicate, options)
96
+ cache.fetch_or_store(cache_key(predicate, options).hash) do
97
+ text, meta = lookup(predicate, options)
101
98
  [Template[text], meta] if text
102
99
  end
103
100
  end
104
101
  alias_method :[], :call
105
102
 
103
+ if ::Hash.instance_methods.include?(:slice)
104
+ def cache_key(predicate, options)
105
+ [predicate, options.slice(*CACHE_KEYS)]
106
+ end
107
+ else
108
+ def cache_key(predicate, options)
109
+ [predicate, options.select { |key,| CACHE_KEYS.include?(key) }]
110
+ end
111
+ end
112
+
106
113
  # Try to find a message for the given predicate and its options
107
114
  #
108
115
  # @api private
@@ -161,9 +168,14 @@ module Dry
161
168
  config.root
162
169
  end
163
170
 
171
+ # @api private
172
+ def hash
173
+ @hash ||= config.hash
174
+ end
175
+
164
176
  # @api private
165
177
  def cache
166
- @cache ||= self.class.cache[self]
178
+ @cache ||= self.class.cache[hash]
167
179
  end
168
180
 
169
181
  # @api private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-08 00:00:00.000000000 Z
11
+ date: 2019-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby