Class: ActiveModel::BetterErrors::HumanMessageReporter

Inherits:
MessageReporter show all
Defined in:
lib/active_model/better_errors/human_message_reporter.rb

Overview

HumanMessageReporter

Instance Attribute Summary

Attributes inherited from Reporter

#collection

Instance Method Summary collapse

Methods inherited from Reporter

#base, #initialize

Constructor Details

This class inherits a constructor from ActiveModel::BetterErrors::Reporter

Instance Method Details

#full_message(attribute, message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_model/better_errors/human_message_reporter.rb', line 18

def full_message(attribute, message)
  return message if attribute == :base
  str = attribute.to_s.gsub('.', '_').humanize
  str = base.class.human_attribute_name(attribute, default: str)

  I18n.t(
    'errors.format',
    default:    '%{attribute} %{message}',
    attribute:  str,
    message:    message
  )
end

#full_messagesObject



9
10
11
12
13
14
15
16
# File 'lib/active_model/better_errors/human_message_reporter.rb', line 9

def full_messages
  @collection.map do |attribute, error_message|
    message = ::ActiveModel::BetterErrors.format_message(
      base, error_message
    )
    full_message attribute, message
  end
end

#generate_message(attribute, type = :invalid, options = {}) ⇒ Object

This method is not used internally. This is for API Compatibility with ActiveModel::Errors only



33
34
35
36
# File 'lib/active_model/better_errors/human_message_reporter.rb', line 33

def generate_message(attribute, type = :invalid, options = {})
  error_message = ErrorMessage.build(base, attribute, type, options)
  ::ActiveModel::BetterErrors.format_message(base, error_message)
end