dry-schema 1.0.2 → 1.0.3

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: 1bf48198c497de44b2a8511ef4ba4189ea9cb94a7eeef95dfd816702e867636b
4
- data.tar.gz: 2189a1c1c034de218601a2cafeff4fe0d4d1a5b5162b9ceed116ec0cd0989b2a
3
+ metadata.gz: 1867ad3cc77ca7f40338a9af423ebbdeb226c677e54fa2681af2efe43cc098e7
4
+ data.tar.gz: 2b0a981aaaab80619e4e79b5428961fa8f68e47796c171771531fa9263f3a487
5
5
  SHA512:
6
- metadata.gz: d56209a51e4f48ceb29e6c9f7302d7ba184c13f1db0163d05754a95b7c3e7642e47cdb5cf89989dbc419747a48d4623b4906c7dd532700e6980a02420a361bbe
7
- data.tar.gz: df81a0c7769187c928923de9750e1111b0acf8bc8324a1a6f50bffa3a4bf9c2c2edceb78c2de3d69d7962778450ba1f4745d79d979df46a9e4b3daaf388f51e0
6
+ metadata.gz: 8296a4a2e9d5972fcac050407a76c6c9ac477415f2abfeb2d5005f71a3ac6ee32101edfb785ef51048fdd1d6bf70ec24fcc53c5883004169ec20af2291e138b5
7
+ data.tar.gz: 88d64217d50a50c642a23713cd4f2a865ed16dd7da73a73dc085f7324daae9869c06c1e4024ecc2b973aea7097daae8037020fce7121cafab08732faa9362fa2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # v1.0.3 2019-05-21
2
+
3
+ ### Fixed
4
+
5
+ * `Object#hash` is no longer used to calculate cache keys due to a potential risk of having hash collisions (solnic)
6
+ * Predicate arguments are used again for template cache keys (solnic)
7
+ * `I18n` messages backend no longer evaluates templates twice (solnic)
8
+
9
+ [Compare v1.0.2...v1.0.3](https://github.com/dry-rb/dry-schema/compare/v1.0.2...v1.0.3)
10
+
1
11
  # v1.0.2 2019-05-12
2
12
 
3
13
  ### Fixed
@@ -45,8 +45,6 @@ module Dry
45
45
  String => 'string'
46
46
  )
47
47
 
48
- CACHE_KEYS = %i[path message_type val_type arg_type locale].freeze
49
-
50
48
  # @api private
51
49
  def self.cache
52
50
  @cache ||= Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new }
@@ -93,23 +91,13 @@ module Dry
93
91
  #
94
92
  # @api public
95
93
  def call(predicate, options)
96
- cache.fetch_or_store(cache_key(predicate, options).hash) do
94
+ cache.fetch_or_store([predicate, options.reject { |k,| k.equal?(:input) }]) do
97
95
  text, meta = lookup(predicate, options)
98
96
  [Template[text], meta] if text
99
97
  end
100
98
  end
101
99
  alias_method :[], :call
102
100
 
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
-
113
101
  # Try to find a message for the given predicate and its options
114
102
  #
115
103
  # @api private
@@ -168,14 +156,9 @@ module Dry
168
156
  config.root
169
157
  end
170
158
 
171
- # @api private
172
- def hash
173
- @hash ||= config.hash
174
- end
175
-
176
159
  # @api private
177
160
  def cache
178
- @cache ||= self.class.cache[hash]
161
+ @cache ||= self.class.cache[self]
179
162
  end
180
163
 
181
164
  # @api private
@@ -29,7 +29,7 @@ module Dry
29
29
  #
30
30
  # @api public
31
31
  def get(key, options = EMPTY_HASH)
32
- t.(key, options) if key
32
+ t.(key, locale: options.fetch(:locale, default_locale)) if key
33
33
  end
34
34
 
35
35
  # Check if given key is defined
@@ -14,7 +14,7 @@ module Dry
14
14
  class Template
15
15
  include Dry::Equalizer(:text)
16
16
 
17
- TOKEN_REGEXP = /%{([\w\d]*)}/
17
+ TOKEN_REGEXP = /%{(\w*)}/
18
18
 
19
19
  # !@attribute [r] text
20
20
  # @return [String]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = '1.0.2'
5
+ VERSION = '1.0.3'
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.2
4
+ version: 1.0.3
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-12 00:00:00.000000000 Z
11
+ date: 2019-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby