dry-schema 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/dry/schema/messages/abstract.rb +21 -9
- data/lib/dry/schema/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: 1bf48198c497de44b2a8511ef4ba4189ea9cb94a7eeef95dfd816702e867636b
|
4
|
+
data.tar.gz: 2189a1c1c034de218601a2cafeff4fe0d4d1a5b5162b9ceed116ec0cd0989b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
99
|
-
cache.fetch_or_store(
|
100
|
-
text, meta = lookup(
|
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[
|
178
|
+
@cache ||= self.class.cache[hash]
|
167
179
|
end
|
168
180
|
|
169
181
|
# @api private
|
data/lib/dry/schema/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2019-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|