lib/errawr/error.rb in errawr-1.0.0 vs lib/errawr/error.rb in errawr-1.1.0

- old
+ new

@@ -1,29 +1,37 @@ module Errawr class Error < StandardError - attr_reader :key, :context, :message + attr_reader :key, :context, :metadata, :message def initialize(key = :unknown, context = {}) @key = key @i18n = I18n.t('errawr.' + @key.to_s) process_context(context) + process_metadata(context) process_message end private def process_context(context) if @i18n.kind_of?(Hash) @context = @i18n.merge(context) - @context.delete(:error) + @context.delete(:metadata) else @context = {} end end + def process_metadata(context) + if @i18n.kind_of?(Hash) + context = @i18n.merge(context) + end + @metadata = context.fetch(:metadata, {}) + end + def process_message if @i18n.kind_of?(Hash) - key = 'errawr.' + @key.to_s + '.error.message' - @message = I18n.t(key, @context, { default: I18n.t('errawr.unknown', @context) }) + key = 'errawr.' + @key.to_s + '.message' + @message = I18n.t(key, @context.merge({ default: I18n.t('errawr.unknown', @context) })) else @message = I18n.t('errawr.' + @key.to_s, @context) end end end \ No newline at end of file