lib/dry/schema/messages/yaml.rb in dry-schema-0.1.1 vs lib/dry/schema/messages/yaml.rb in dry-schema-0.2.0

- old
+ new

@@ -14,15 +14,16 @@ attr_reader :data # @api private configure do |config| - config.root = '%{locale}.errors'.freeze + config.root = '%{locale}.dry_schema.errors'.freeze + config.rule_lookup_paths = config.rule_lookup_paths.map { |path| "%{locale}.dry_schema.#{path}" } end # @api private - def self.load(paths = config.paths) + def self.build(paths = config.paths) new(paths.map { |path| load_file(path) }.reduce(:merge)) end # @api private def self.load_file(path) @@ -49,19 +50,27 @@ # # @return [String] # # @api public def get(key, options = {}) - data[key % { locale: options.fetch(:locale, default_locale) }] + evaluated_key = key.include?('%{locale}') ? + key % { locale: options.fetch(:locale, default_locale) } : + key + + data[evaluated_key] end # Check if given key is defined # # @return [Boolean] # # @api public def key?(key, options = {}) - data.key?(key % { locale: options.fetch(:locale, default_locale) }) + evaluated_key = key.include?('%{locale}') ? + key % { locale: options.fetch(:locale, default_locale) } : + key + + data.key?(evaluated_key) end # Merge messages from an additional path # # @param [String] path