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
- DICTIONARY =
The states to be translated with their dictionary names
{ true => :truthy, false => :falsey }
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.
-
.scope(klass) ⇒ Array<Symbol>
Provides a scope for the class.
Instance Attribute Details
#assertion ⇒ Class (readonly)
Returns the assertion whose state should be translated.
62 63 64 |
# File 'lib/assertion/translator.rb', line 62 def assertion @assertion end |
#scope ⇒ Class (readonly)
Returns the assertion whose state should be translated.
56 57 58 |
# File 'lib/assertion/translator.rb', line 56 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 for the gem-specific scope for the current class
89 90 91 |
# File 'lib/assertion/translator.rb', line 89 def call(state, args = {}) I18n.translate DICTIONARY[state ? true : false], args.merge(scope: scope) end |
.initialize(assertion) ⇒ Object
73 74 75 76 77 |
# File 'lib/assertion/translator.rb', line 73 def initialize(assertion) @assertion = assertion @scope = self.class.scope(assertion) freeze end |
.new(assertion) ⇒ Assertion::Translator
Creates a state translator for the given assertion class
|
# File 'lib/assertion/translator.rb', line 64
|