Class: Aequitas::MessageTransformer::DefaultStatic
- Inherits:
-
Aequitas::MessageTransformer
- Object
- Aequitas::MessageTransformer
- Aequitas::MessageTransformer::DefaultStatic
- Defined in:
- lib/aequitas/message_transformer.rb
Class Attribute Summary collapse
-
.error_messages ⇒ Hash{Symbol=>String}
Gets the hash of error messages used to transform violations.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ DefaultStatic
constructor
A new instance of DefaultStatic.
- #transform(violation) ⇒ Object
Methods inherited from Aequitas::MessageTransformer
Constructor Details
#initialize ⇒ DefaultStatic
Returns a new instance of DefaultStatic.
94 95 96 |
# File 'lib/aequitas/message_transformer.rb', line 94 def initialize require 'dm-core' end |
Class Attribute Details
.error_messages ⇒ Hash{Symbol=>String}
Gets the hash of error messages used to transform violations.
69 70 71 |
# File 'lib/aequitas/message_transformer.rb', line 69 def @error_messages end |
Class Method Details
.error_message(violation_type, attribute_name, violation_values) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/aequitas/message_transformer.rb', line 85 def self.(violation_type, attribute_name, violation_values) if = self.[violation_type] attribute_name = ::DataMapper::Inflector.humanize(attribute_name) % [attribute_name, *violation_values].flatten else violation_type.to_s end end |
Instance Method Details
#transform(violation) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/aequitas/message_transformer.rb', line 98 def transform(violation) raise ArgumentError, "+violation+ must be specified" if violation.nil? attribute_name = violation.attribute_name self.class.(violation.type, attribute_name, violation.values) end |