Class: ActiveModel::ErrorCollecting::HumanMessageReporter

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

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::ErrorCollecting::Reporter

Instance Method Details

#full_message(attribute, message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/active_model/error_collecting/human_message_reporter.rb', line 12

def full_message(attribute, message)
  return message if attribute == :base
  attr_name = attribute.to_s.gsub('.', '_').humanize
  attr_name = base.class.human_attribute_name(attribute, :default => attr_name)
  I18n.t(:"errors.format", {
    :default   => "%{attribute} %{message}",
    :attribute => attr_name,
    :message   => message
  })
end

#full_messagesObject



4
5
6
7
8
9
10
# File 'lib/active_model/error_collecting/human_message_reporter.rb', line 4

def full_messages
  @collection.map do |attribute, error_message|
    formatter = HumanMessageFormatter.new(base, error_message)
    message   = formatter.format_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



25
26
27
28
29
# File 'lib/active_model/error_collecting/human_message_reporter.rb', line 25

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