Skip to content

Latest commit

 

History

History
111 lines (82 loc) · 4.67 KB

README_EN.md

File metadata and controls

111 lines (82 loc) · 4.67 KB

ENGLISH | PORTUGUÊS

🐍 PyFlunt: Domain Notification Pattern

Python implementation of Domain Notification Pattern inspired by Flunt (.NET)

Último Lançamento no PyPI python Downloads License: MIT Gitter

Avaliação de Segurança Avaliação de Confiabilidade Avaliação de Manutenibilidade Bugs Vulnerabilidades Code Smells

Flunt is a way to implement a notification pattern in your application to centralize errors and changes in certain actions and entities.

Flunt was born out of two needs: implementing the Domain Notification Pattern to replace domain-level exceptions in the application and reducing the amount of IFs (complexity) by using a contract-based approach.

Thus, basically what Flunt does is add a list of Notifications to your class and various methods to interact with it.

➡️ How to use

🔧 Installation

pip install flunt

🔔 Notifiable

from flunt.notifications.notifiable import Notifiable
from flunt.validations.contract import Contract

class Name(Notifiable):
    def __init__(self, name):
        super().__init__()

        if len(name) > 3:
            self.add_notification(
                Notification(field='name', message='invalid name')
            )

        self._name = name

📜 Contract

"""Module Value Objects."""
from flunt.notifications.notifiable import Notifiable
from flunt.validations.contract import Contract


class Name(Notifiable):
    """Class Value Object Name."""

    def __init__(self, first_name, last_name):
        """Found 'Constructor'."""
        super().__init__()
        self.first_name = first_name
        self.last_name = last_name
        self.add_notifications(
            Contract()
            .requires(self.first_name, 'first name')
            .requires(self.last_name, 'last name')
            .is_greater_than(
                value=self.first_name,
                comparer=3,
                key="first_name",
                message="Mínimo de 3 caracteres",
            )
            .is_greater_than(
                value=self.last_name,
                comparer=3,
                key="last_name",
                message="Mínimo de 3 caracteres",
            )
            .get_notifications()
        )


nome = Name('Emerson', 'Delatorre')
if not nome.is_valid():
    for notification in nome.get_notifications():
        print(notification)

Contributing

Please refer to our DevGuide at the following link: CONTRIBUTING

Changelog

Please refer to our changelog at the following link: CHANGELOG

📄 License

This project contains the MIT license. See the file LICENSE.

Mods