Class: NexusCqrs::BaseMessage
- Inherits:
-
Object
- Object
- NexusCqrs::BaseMessage
- Defined in:
- lib/nexus_cqrs/base_message.rb
Overview
All messages passed through the message bus will extend this class. Commands and Queries are both extended types of ‘BaseMessage`. This is mainly used to store metadata for Commands/Queries (such as the user context), as well as helper methods for retrieving the policy method for this Command/Query/Message
Direct Known Subclasses
Instance Method Summary collapse
-
#demodularised_class_name ⇒ String
Helper method for retrieving the demodularised name of the class used to define the auth policy for this message.
-
#metadata ⇒ Hash
Getter for retrieving the metadata on this message.
-
#policy_class ⇒ String
deprecated
Deprecated.
This used to be used to authorise policies before they hit the command bus - requiring a new policy for every message. E.g. ‘DeleteModPolicy`, `UpdateModPolicy`, `CreateModPolicy` etc. It is now recommended to simple call `authorise` within the handler as it is far more flexible
-
#set_metadata(key, value) ⇒ Object
Sets metadata on this message.
Instance Method Details
#demodularised_class_name ⇒ String
Helper method for retrieving the demodularised name of the class used to define the auth policy for this message
50 51 52 |
# File 'lib/nexus_cqrs/base_message.rb', line 50 def demodularised_class_name self.class.name.split('::').last end |
#metadata ⇒ Hash
Getter for retrieving the metadata on this message
25 26 27 |
# File 'lib/nexus_cqrs/base_message.rb', line 25 def @metadata || {} end |
#policy_class ⇒ String
This used to be used to authorise policies before they hit the command bus - requiring a new policy for every message. E.g. ‘DeleteModPolicy`, `UpdateModPolicy`, `CreateModPolicy` etc. It is now recommended to simple call `authorise` within the handler as it is far more flexible
Helper method for retrieving the name of the class used to define the auth policy for this message
39 40 41 |
# File 'lib/nexus_cqrs/base_message.rb', line 39 def policy_class demodularised_class_name + 'Policy' end |
#set_metadata(key, value) ⇒ Object
Sets metadata on this message.
16 17 18 19 |
# File 'lib/nexus_cqrs/base_message.rb', line 16 def (key, value) @metadata = {} unless @metadata @metadata[key.to_sym] = value end |