Class: NxtSchema::Validators::ErrorMessages
- Inherits:
-
Object
- Object
- NxtSchema::Validators::ErrorMessages
- Defined in:
- lib/nxt_schema/validators/error_messages.rb
Class Method Summary collapse
- .files ⇒ Object
- .load(paths = files) ⇒ Object
- .resolve(locale, key, **options) ⇒ Object
- .values ⇒ Object
- .values=(value) ⇒ Object
Class Method Details
.files ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/nxt_schema/validators/error_messages.rb', line 30 def files @files ||= begin files = Dir.entries(File.('../error_messages/', __FILE__)).map do |filename| File.("../error_messages/#{filename}", __FILE__) end files.select { |f| !File.directory? f } end end |
.load(paths = files) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/nxt_schema/validators/error_messages.rb', line 13 def load(paths = files) Array(paths).each do |path| new_values = YAML.load(ERB.new(File.read(path)).result).with_indifferent_access self.values = values.deep_merge!(new_values) end end |
.resolve(locale, key, **options) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/nxt_schema/validators/error_messages.rb', line 20 def resolve(locale, key, **) = begin values.fetch(locale).fetch(key) rescue KeyError raise "Could not resolve error message for #{locale}->#{key}" end % end |
.values ⇒ Object
5 6 7 |
# File 'lib/nxt_schema/validators/error_messages.rb', line 5 def values @values ||= {} end |
.values=(value) ⇒ Object
9 10 11 |
# File 'lib/nxt_schema/validators/error_messages.rb', line 9 def values=(value) @values = value end |