Class: Aequitas::MessageTransformer::DefaultI18n
- Inherits:
-
Aequitas::MessageTransformer
- Object
- Aequitas::MessageTransformer
- Aequitas::MessageTransformer::DefaultI18n
- Defined in:
- lib/aequitas/message_transformer.rb
Overview
class Default
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ DefaultI18n
constructor
A new instance of DefaultI18n.
- #transform(violation) ⇒ Object
Methods inherited from Aequitas::MessageTransformer
Constructor Details
#initialize ⇒ DefaultI18n
Returns a new instance of DefaultI18n.
95 96 97 |
# File 'lib/aequitas/message_transformer.rb', line 95 def initialize require 'i18n' end |
Instance Attribute Details
#i18n_namespace ⇒ Object
121 122 123 |
# File 'lib/aequitas/message_transformer.rb', line 121 def i18n_namespace @i18n_namespace || 'aequitas.validation.errors' end |
Instance Method Details
#transform(violation) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/aequitas/message_transformer.rb', line 99 def transform(violation) raise ArgumentError, "+violation+ must be specified" if violation.nil? resource = violation.resource model_name = resource.model.model_name attribute_name = violation.attribute_name # TODO: Include attribute value in Violation; it may have changed by now # attribute_value = violation.attribute_value = { :model => ::I18n.translate("models.#{model_name}"), :attribute => ::I18n.translate("attributes.#{model_name}.#{attribute_name}"), # TODO: Include attribute value in Violation; it may have changed by now :value => resource.validation_attribute_value(attribute_name) }.merge(violation.info) ::I18n.translate("#{i18n_namespace}.#{violation.type}", ) end |