lib/dry/schema/messages/yaml.rb in dry-schema-1.6.2 vs lib/dry/schema/messages/yaml.rb in dry-schema-1.7.0

- old
+ new

@@ -70,10 +70,15 @@ def self.cache @cache ||= Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new } end # @api private + def self.source_cache + @source_cache ||= Concurrent::Map.new + end + + # @api private def initialize(data: EMPTY_HASH, config: nil) super() @data = data @config = config if config @t = proc { |key, locale: default_locale| get("%<locale>s.#{key}", locale: locale) } @@ -177,10 +182,12 @@ @cache ||= self.class.cache[self] end # @api private def load_translations(path) - data = self.class.flat_hash(YAML.load_file(path)) + data = self.class.source_cache.fetch_or_store(path) do + self.class.flat_hash(YAML.load_file(path)).freeze + end return data unless custom_top_namespace?(path) data.map { |k, v| [k.gsub(DEFAULT_MESSAGES_ROOT, config.top_namespace), v] }.to_h end