Class: Sheetah::Messaging::MessageVariant Abstract
- Defined in:
- lib/sheetah/messaging/message_variant.rb
Overview
While a Message represents any kind of message, MessageVariant represents any subset of messages that share the same code.
The code of a message variant can and should be defined at the class level, given that it won’t differ among the instances (and a validation is defined to enforce that invariant). MessageVariant should be considered an abstract class, and its subclasses should define their own ‘CODE` constant, which will be read by MessageVariant.code.
As far as the other methods are concerned, MessageVariant.code should be considered the only source of truth when it comes to reading the code assigned to a message variant. The fact that MessageVariant.code is actually implemented using a dynamic resolution of the class’ ‘CODE` constant is an implementation detail stemming from the fact that documentation tools such as YARD will highlight constants, as opposed to instance variables of a class for example. Using a constant is therefore meant to provide better documentation, and it should not be relied upon otherwise.
Direct Known Subclasses
Sheetah::Messaging::Messages::CleanedString, Sheetah::Messaging::Messages::DuplicatedHeader, Sheetah::Messaging::Messages::InvalidHeader, Sheetah::Messaging::Messages::MissingColumn, Sheetah::Messaging::Messages::MustBeArray, Sheetah::Messaging::Messages::MustBeBoolsy, Sheetah::Messaging::Messages::MustBeDate, Sheetah::Messaging::Messages::MustBeEmail, Sheetah::Messaging::Messages::MustBeString, Sheetah::Messaging::Messages::MustExist, Sheetah::Messaging::Messages::SheetError
Instance Attribute Summary
Attributes inherited from Message
#code, #code_data, #scope, #scope_data, #severity
Class Method Summary collapse
-
.code ⇒ String
Reads the code assigned to the class (and its instances).
-
.new(**opts) ⇒ Object
Simplifies the initialization of a variant.
Methods inherited from Message
#==, #initialize, #to_h, #to_s
Methods included from Validations
Constructor Details
This class inherits a constructor from Sheetah::Messaging::Message
Class Method Details
.code ⇒ String
Reads the code assigned to the class (and its instances)
27 28 29 |
# File 'lib/sheetah/messaging/message_variant.rb', line 27 def self.code self::CODE end |
.new(**opts) ⇒ Object
Simplifies the initialization of a variant
Contrary to the requirements of Sheetah::Messaging::Message#initialize, new doesn’t require the caller to pass the ‘:code` keyword argument, as it is capable of prodividing it automatically (from reading code).
36 37 38 |
# File 'lib/sheetah/messaging/message_variant.rb', line 36 def self.new(**opts) super(code: code, **opts) end |