Class: Lifer::Message
- Inherits:
-
Object
- Object
- Lifer::Message
- Defined in:
- lib/lifer/message.rb
Overview
This message class lets us output rich messages to STDOUT without muddying up the Lifer source code with ad hoc ‘puts` statements. Using this interface helps us ensure that translations are accounted for, and it lets us format errors and log messages in a consistent way.
If the program is in test mode, this means the message should not be output to STDOUT.
Constant Summary collapse
- ANSI_COLOURS =
ANSI colour codes for colours used by different messages.
{red: "31"}
Class Method Summary collapse
-
.error(translation_key, test_mode: test_mode?, , **args) ⇒ void
Outputs a red error message into STDOUT for higher visibility.
-
.log(translation_key, test_mode: test_mode?, , **args) ⇒ void
Outputs a log message into STDOUT.
Class Method Details
.error(translation_key, test_mode: test_mode?, , **args) ⇒ void
This method returns an undefined value.
Outputs a red error message into STDOUT for higher visibility. Note that this is still just a message, and the program might not exit due to an exception having been raised.
26 27 28 29 30 31 32 33 |
# File 'lib/lifer/message.rb', line 26 def error(translation_key, test_mode: test_mode?, **args) return if test_mode prefix = I18n.t("message.prefix.error") = I18n.t!(translation_key, **args) puts colorize(("%s: %s" % [prefix, ]), :red) end |
.log(translation_key, test_mode: test_mode?, , **args) ⇒ void
This method returns an undefined value.
Outputs a log message into STDOUT.
44 45 46 47 48 |
# File 'lib/lifer/message.rb', line 44 def log(translation_key, test_mode: test_mode?, **args) return if test_mode puts I18n.t!(translation_key, **args) end |