Class: Assertion::Translator
- Inherits:
-
Object
- Object
- Assertion::Translator
- Defined in:
- lib/assertion/translator.rb
Overview
Module defines how to translate messages describing the desired state of the current assertion
You need to declare a hash of attributes to be added to the translation.
Constant Summary collapse
- ROOT =
The gem-specific root scope for translations
:assertion
Instance Attribute Summary collapse
-
#assertion ⇒ Class
readonly
The assertion whose state should be translated.
-
#scope ⇒ Class
readonly
The assertion whose state should be translated.
Class Method Summary collapse
-
.call(state, args = {}) ⇒ String
Returns the message describing the desired state of given assertion.
- .initialize(assertion) ⇒ Object
-
.new(assertion) ⇒ Assertion::Translator
Creates a state translator for the given assertion class.
Instance Attribute Details
#assertion ⇒ Class (readonly)
Returns the assertion whose state should be translated.
46 47 48 |
# File 'lib/assertion/translator.rb', line 46 def assertion @assertion end |
#scope ⇒ Class (readonly)
Returns the assertion whose state should be translated.
40 41 42 |
# File 'lib/assertion/translator.rb', line 40 def scope @scope end |
Class Method Details
.call(state, args = {}) ⇒ String
Returns the message describing the desired state of given assertion
The translation is provided in a gem-specific scope for the current class
72 73 74 |
# File 'lib/assertion/translator.rb', line 72 def call(state, args = {}) I18n.translate state, args.merge(scope: scope) end |
.initialize(assertion) ⇒ Object
57 58 59 60 61 |
# File 'lib/assertion/translator.rb', line 57 def initialize(assertion) @assertion = assertion @scope = "#{ROOT}.#{Inflecto.underscore assertion}" IceNine.deep_freeze(self) end |
.new(assertion) ⇒ Assertion::Translator
Creates a state translator for the given assertion class
|
# File 'lib/assertion/translator.rb', line 48
|