generic-events-manager


Namegeneric-events-manager JSON
Version 0.0.6 PyPI version JSON
download
home_page
SummaryGeneric class for managing events generated by an application
upload_time2023-01-05 20:54:49
maintainer
docs_urlNone
authorTatianno Alves
requires_python
licenseMIT License
keywords manager observer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            #  GenericEventsManager

## Overview

It is a generic class for managing events generated by an application.


## Installing GenericEventsManager and Supported Versions

GenericEventsManager is available on PyPI:

`$ python -m pip install generic-events-manager`

GenericEventsManager officially supports Python 3.8+.

## Cloning the repository

`$ git clone https://github.com/tatianno/generic-events-manager.git`

## Example

```
from events_manager import GenericEventsManager
from events_manager.entities import GenericObserver


class CustomObserver(GenericObserver):

    def _exec_routine_update_obj(self, obj_new: GenericEventsManager.EventObject, obj_old: GenericEventsManager.EventObject) -> None:
        '''
        Method called each time the observed object changes state
        '''
        print(f'The object {obj_new.key} has been updated with the state {obj_new.state}')
        print(f'The previous state was {obj_old.state}')

    def _exec_routine_delete_obj(self, obj: GenericEventsManager.EventObject) -> None:
        '''
        Method called when observed object is deleted
        '''
        print(f'The object {obj.key} has been deleted')


class CustomEventsManager(GenericEventsManager):

    class EventObject(GenericEventsManager.EventObject):
        observer_class = CustomObserver

    def create(self, entity: EventObject) -> None:
        self.perfom_create(entity)

    def update(self, entity: EventObject) -> None:
        old_entity = self.get(entity.get_key())
        self.perfom_update(entity, old_entity)

    def delete(self, entity: EventObject) -> None:
        self.perfom_destroy(entity)


# Instantiating the Event Handler and Observer
events_manager = CustomEventsManager()
observer = CustomObserver()

# Dictionary containing event data
data = {
    'state' : 'ON',
    'key' : 'k1'
}

# Updating the object with the received event data
response = events_manager.event_update(data)

# Subscribing observer
obj = events_manager.get('k1')
obj.subscribe(observer)

# Dictionary containing event data
data = {
    'state' : 'OFF',
    'key' : 'k1'
}

# Updating the object with the received event data
response = events_manager.event_update(data)

# Deleting object
obj = events_manager.get('k1')
events_manager.delete(obj)
```



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "generic-events-manager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "manager observer",
    "author": "Tatianno Alves",
    "author_email": "tferreiraalves@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "#  GenericEventsManager\n\n## Overview\n\nIt is a generic class for managing events generated by an application.\n\n\n## Installing GenericEventsManager and Supported Versions\n\nGenericEventsManager is available on PyPI:\n\n`$ python -m pip install generic-events-manager`\n\nGenericEventsManager officially supports Python 3.8+.\n\n## Cloning the repository\n\n`$ git clone https://github.com/tatianno/generic-events-manager.git`\n\n## Example\n\n```\nfrom events_manager import GenericEventsManager\nfrom events_manager.entities import GenericObserver\n\n\nclass CustomObserver(GenericObserver):\n\n    def _exec_routine_update_obj(self, obj_new: GenericEventsManager.EventObject, obj_old: GenericEventsManager.EventObject) -> None:\n        '''\n        Method called each time the observed object changes state\n        '''\n        print(f'The object {obj_new.key} has been updated with the state {obj_new.state}')\n        print(f'The previous state was {obj_old.state}')\n\n    def _exec_routine_delete_obj(self, obj: GenericEventsManager.EventObject) -> None:\n        '''\n        Method called when observed object is deleted\n        '''\n        print(f'The object {obj.key} has been deleted')\n\n\nclass CustomEventsManager(GenericEventsManager):\n\n    class EventObject(GenericEventsManager.EventObject):\n        observer_class = CustomObserver\n\n    def create(self, entity: EventObject) -> None:\n        self.perfom_create(entity)\n\n    def update(self, entity: EventObject) -> None:\n        old_entity = self.get(entity.get_key())\n        self.perfom_update(entity, old_entity)\n\n    def delete(self, entity: EventObject) -> None:\n        self.perfom_destroy(entity)\n\n\n# Instantiating the Event Handler and Observer\nevents_manager = CustomEventsManager()\nobserver = CustomObserver()\n\n# Dictionary containing event data\ndata = {\n    'state' : 'ON',\n    'key' : 'k1'\n}\n\n# Updating the object with the received event data\nresponse = events_manager.event_update(data)\n\n# Subscribing observer\nobj = events_manager.get('k1')\nobj.subscribe(observer)\n\n# Dictionary containing event data\ndata = {\n    'state' : 'OFF',\n    'key' : 'k1'\n}\n\n# Updating the object with the received event data\nresponse = events_manager.event_update(data)\n\n# Deleting object\nobj = events_manager.get('k1')\nevents_manager.delete(obj)\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Generic class for managing events generated by an application",
    "version": "0.0.6",
    "split_keywords": [
        "manager",
        "observer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "974bb95e684121e131f883d630f8dd6f197256e4cf088e6f1ce151c8285428f4",
                "md5": "e17820f53d0c2475187949f3358091fe",
                "sha256": "448351f2cef0d116015f015fa4dc80cfaebc2d19e5ea51f6a8c2b24465482418"
            },
            "downloads": -1,
            "filename": "generic_events_manager-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e17820f53d0c2475187949f3358091fe",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4855,
            "upload_time": "2023-01-05T20:54:49",
            "upload_time_iso_8601": "2023-01-05T20:54:49.959591Z",
            "url": "https://files.pythonhosted.org/packages/97/4b/b95e684121e131f883d630f8dd6f197256e4cf088e6f1ce151c8285428f4/generic_events_manager-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-05 20:54:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "generic-events-manager"
}
        
Elapsed time: 0.16232s