Class: ActiveModel::ErrorCollecting::HumanMessageFormatter
- Inherits:
-
Object
- Object
- ActiveModel::ErrorCollecting::HumanMessageFormatter
- Extended by:
- Forwardable
- Defined in:
- lib/active_model/error_collecting/human_message_formatter.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
Instance Method Summary collapse
- #format_message ⇒ Object
-
#initialize(base, error_message) ⇒ HumanMessageFormatter
constructor
A new instance of HumanMessageFormatter.
- #type ⇒ Object
Constructor Details
#initialize(base, error_message) ⇒ HumanMessageFormatter
Returns a new instance of HumanMessageFormatter.
10 11 12 |
# File 'lib/active_model/error_collecting/human_message_formatter.rb', line 10 def initialize(base, ) @base, = base, end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
8 9 10 |
# File 'lib/active_model/error_collecting/human_message_formatter.rb', line 8 def base @base end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
8 9 10 |
# File 'lib/active_model/error_collecting/human_message_formatter.rb', line 8 def end |
Instance Method Details
#format_message ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_model/error_collecting/human_message_formatter.rb', line 18 def return if && .type.nil? keys = i18n_keys key = keys.shift value = (attribute != :base ? base.send(:read_attribute_for_validation, attribute) : nil) = { :default => keys, :model => base.class.model_name.human, :attribute => base.class.human_attribute_name(attribute), :value => value }.merge(self.) I18n.translate key, end |
#type ⇒ Object
14 15 16 |
# File 'lib/active_model/error_collecting/human_message_formatter.rb', line 14 def type .type || :invalid end |