Skip to content

Improve messaging#2

Open
ghost wants to merge 3 commits intomasterfrom
improve-messaging
Open

Improve messaging#2
ghost wants to merge 3 commits intomasterfrom
improve-messaging

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Sep 1, 2023

For all messages, given its code, the associated data should have a fixed, known structure.

Currently, the code and data structure aren't clearly exposed by the library API. Codes are referenced using string literals, and data structures are not checked automatically. As a primary consequence, the result is error-prone, as the burden of keeping messages consistent falls entirely on the shoulders of the developer. Also, codes and data structures can't be easily documented, and library users are forced to go through the code base and hope not to miss a code to obtain a list of the messages they'll have to handle.

This PR introduces a new message validation API, that should be used to answer both needs:

  • Payloads can be validated using custom checks implemented in their dedicated class
  • Payloads can be documented using Ruby documentation tools (such as YARD)

This comes at the price of breaking the Messenger API, but we'd better pay that cost now rather than later.

@ghost ghost self-assigned this Sep 1, 2023
@ghost ghost force-pushed the improve-messaging branch 2 times, most recently from 49a7256 to 55fdc1f Compare September 7, 2023 10:42
Add custom validations on Message classes to guarantee at runtime their
structural integrity.

Such validations are opt-out, because they are considered useful and
lightweight enough for most use cases. Still, they can be disabled using
a global configuration parameter if need be.
@ghost ghost force-pushed the improve-messaging branch from 6d9856d to daca9d2 Compare September 11, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants