Class: Aequitas::MessageTransformer Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/aequitas/message_transformer.rb

Overview

This class is abstract.

Subclass and override #transform to implement a custom message transformer. Use Violation.default_transformer= to set a new default message transformer or pass the transformer to Violation#message.

Transforms Violations to error message strings.

Direct Known Subclasses

DefaultI18n, DefaultStatic

Defined Under Namespace

Classes: DefaultI18n, DefaultStatic

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultMessageTransformer

Get the default MessageTransformer for this process

Returns:

See Also:

  • {Violation{Violation.default_transformer}


19
20
21
# File 'lib/aequitas/message_transformer.rb', line 19

def self.default
  defined?(::I18n) ? DefaultI18n.new : DefaultStatic.new
end

Instance Method Details

#transform(violation) ⇒ String

Transforms the specified Violation to an error message string.

Parameters:

  • violation (Violation)

    The Violation to transform.

Returns:

  • (String)

    The transformed message.

Raises:

  • (ArgumentError)

    violation is nil.



33
34
35
# File 'lib/aequitas/message_transformer.rb', line 33

def transform(violation)
  raise NotImplementedError, "#{self.class}#transform has not been implemented"
end