{ "info": { "author": "Rudinei Goi Roecker", "author_email": "rudinei.roecker@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Application Frameworks" ], "description": "# Py-Macaroni\n\nThis is a library to help you avoid\n[Spaghetti Code](https://en.wikipedia.org/wiki/Spaghetti_code). It helps you\nexpress your application logic in a testable way. The whole idea for this lib\nwas based on some concepts from functional programming and rust, mainly the\n\"unwrap\" concept from rust.\n\n## Why\n\nWhen creating bussiness logic for your application, sometimes it gets hard to\nstructure complex logic in a easy to understand way. To help with that, this\nlibrary was created. The main objective is to help you structure your\napplication in a clean and readable way, enabling future maintenance of the\ncode.\n\nFor example, if you have a CRUD application, some logic will be shared between\nthe Create and Update functions, the lib, in this case, can help by chaining\nfunctions required to implement the main bussiness rule, and makes it easier to\nreuse functions when required.\n\n```python\nimport macaroni as mci\n\nclass BussinessLogic(mci.Macaroni):\n def validate_request(self, data):\n # ...\n\n def check_user_permissions(self, data):\n # ...\n\n def log_operation(self, data):\n # ...\n\n def create_item(self, data):\n # ...\n\n def update_item(self, data):\n # ...\n\n @mci.error\n def handle_error(self, data, error):\n # ...\n\n @mci.exception(DuplicateKey)\n def handle_duplicate_item(self, data, exception):\n # ...\n\n\ndef create_item(data):\n bl = BussinessLogic(data)\n result = (\n bl.validate_request()\n .check_user_permissions()\n .create_item()\n .log_operation()\n .handle_error()\n .handle_duplicate_item()\n .unwrap()\n )\n return result\n\n\ndef update_item(data):\n bl = BussinessLogic(data)\n result = (\n bl.validate_request()\n .check_user_permissions()\n .update_item()\n .log_operation()\n .handle_error()\n .unwrap()\n )\n return result\n```\n\nIt also helps you avoid dealing with error and exception handling on each part\nof your application logic, letting you handle then only at the end of the\napplication execution, automatically skipping steps in your application logic\nwhen an error or exception happens.\n\n## Installation\n\n```\npip install macaroni\n```\n\n## Usage\n\nMore examples can be found in the [./examples](./examples) directory.\n\n```python\nimport macaroni as mci\n\nclass Calculator(mci.Macaroni):\n def increment(self, value, increment=None):\n if increment is None:\n increment = 1\n\n return value + increment\n\n def divide(self, value, denominator):\n if denominator == 0:\n return mci.Error('invalid denominator {0}'.format(denominator))\n\n return value / denominator\n\n def invalid(self, value):\n raise ValueError('invalid data')\n\n\nbase_val = 10\ncalc = Calcultator(base_val)\nresult = calc \\\n .increment(2) \\\n .divide(2) \\\n .unwrap() # this returns the final result\nassert result == 6\n```\n\nError handling:\n\n```python\ncalc = Calculator(10)\nresult = calc \\\n .increment(2) # this is executed \\\n .divide(-3) # this causes an error \\\n .increment() # this is not executed \\\n .unwrap() # returns the error\n\nassert bool(calc.error) == True\nassert result == 'invalid denominator 0'\n```\n\nException handling:\n\n```python\ncalc = Calculator(10)\ntry:\n calc \\\n .increment(2) # this is executed \\\n .invalid() # this causes an exception \\\n .increment() # this is not executed \\\n .unwrap() # the exception ValueError is raised on unwrap\nexcept ValueError:\n pass\n\nassert bool(calc.exception) == True\n```\n\nWhen testing, you can use the parameter `magic=False` to disable the automatic value passing, chaining and error/exception handling:\n\n```python\ndef test_increment():\n calc = Calculator(magic=False)\n result = calc.increment(10, 2)\n assert result == 12\n\ndef test_error():\n calc = Calculator(magic=False)\n result = calc.divide(10, 0)\n assert calc.error is not None\n assert result = 'invalid denominator 0'\n\ndef test_exception()\n calc = Calculator(magic=False)\n\n raised_error = False\n try:\n calc.invalid(10)\n except ValueError:\n raised_error = True\n\n assert raised_error\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/rudineirk/py-macaroni", "keywords": "clean cleancode logic functional", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "macaroni", "package_url": "https://pypi.org/project/macaroni/", "platform": "", "project_url": "https://pypi.org/project/macaroni/", "project_urls": { "Homepage": "https://github.com/rudineirk/py-macaroni" }, "release_url": "https://pypi.org/project/macaroni/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "A lib to help you avoid spaghetti code", "version": "0.0.3" }, "last_serial": 5409868, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "e205d6b07ec3e62fa71741709dda491f", "sha256": "ceb15701213b31cda5c1fd5fc9f375fb205bdcc3e2f43445461e770b70959d26" }, "downloads": -1, "filename": "macaroni-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "e205d6b07ec3e62fa71741709dda491f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5469, "upload_time": "2019-06-17T11:57:44", "url": "https://files.pythonhosted.org/packages/6b/40/995fa65cd3b1a79a10385785b15b04367737bd43f62b68d3a8dbd990ab0d/macaroni-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b556564ea44901acef53e18d22394d5", "sha256": "f36e4e35bb15db81cbffc04687e5b9ecd44f55b13b938c153a9afeb72f8ed1f5" }, "downloads": -1, "filename": "macaroni-0.0.1.tar.gz", "has_sig": false, "md5_digest": "8b556564ea44901acef53e18d22394d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4212, "upload_time": "2019-06-17T11:57:46", "url": "https://files.pythonhosted.org/packages/ad/84/c40c7e3f7248209ab572dd5e0957e0a005ac01fa95c2d998818d6d5cc160/macaroni-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "56bb901e10e1db0809e484fb7e650365", "sha256": "13fb8705c56e3f752c2bfb8c24716dbdb16409d4f3f0e3dec6b1582c27bbb345" }, "downloads": -1, "filename": "macaroni-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "56bb901e10e1db0809e484fb7e650365", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5471, "upload_time": "2019-06-17T12:04:27", "url": "https://files.pythonhosted.org/packages/b9/1b/b15e14720f2adb1b59a1abc3d6ae35b78646a21d261110f0ca477a67e1b4/macaroni-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7a4843540f3fdb610b01717e91a3a4a9", "sha256": "6a4bcec1252416a2dd81fcc61553468561f47229419ab1fda562572fa2a6f639" }, "downloads": -1, "filename": "macaroni-0.0.2.tar.gz", "has_sig": false, "md5_digest": "7a4843540f3fdb610b01717e91a3a4a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4206, "upload_time": "2019-06-17T12:04:29", "url": "https://files.pythonhosted.org/packages/13/f3/06b5a64a0da211a685e15d1c1d66124f544490fbafaf2703d949bcd1b2ca/macaroni-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "d78135fce2b10c0aac9e1df5f4b44324", "sha256": "e6f45b42e62cef03adf67ca7091ba68f8734025590f7ddd09daf66a06b7344ed" }, "downloads": -1, "filename": "macaroni-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "d78135fce2b10c0aac9e1df5f4b44324", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5476, "upload_time": "2019-06-17T12:09:40", "url": "https://files.pythonhosted.org/packages/7b/6b/1a427720633cf48c28d1c94aaae4f5873db11ebd913b259cc8c81e89b4ef/macaroni-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e50f3b3ebc6ed03e575d57314ceef67d", "sha256": "31442aff1a1a5acccea23647d29dac63acf8efea5a2109879156c65ac79b043a" }, "downloads": -1, "filename": "macaroni-0.0.3.tar.gz", "has_sig": false, "md5_digest": "e50f3b3ebc6ed03e575d57314ceef67d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4219, "upload_time": "2019-06-17T12:09:41", "url": "https://files.pythonhosted.org/packages/43/46/661ebe62baba8ba286cea1c2fe66fca86158beca48623804ff01ed7e1d8b/macaroni-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d78135fce2b10c0aac9e1df5f4b44324", "sha256": "e6f45b42e62cef03adf67ca7091ba68f8734025590f7ddd09daf66a06b7344ed" }, "downloads": -1, "filename": "macaroni-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "d78135fce2b10c0aac9e1df5f4b44324", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5476, "upload_time": "2019-06-17T12:09:40", "url": "https://files.pythonhosted.org/packages/7b/6b/1a427720633cf48c28d1c94aaae4f5873db11ebd913b259cc8c81e89b4ef/macaroni-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e50f3b3ebc6ed03e575d57314ceef67d", "sha256": "31442aff1a1a5acccea23647d29dac63acf8efea5a2109879156c65ac79b043a" }, "downloads": -1, "filename": "macaroni-0.0.3.tar.gz", "has_sig": false, "md5_digest": "e50f3b3ebc6ed03e575d57314ceef67d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4219, "upload_time": "2019-06-17T12:09:41", "url": "https://files.pythonhosted.org/packages/43/46/661ebe62baba8ba286cea1c2fe66fca86158beca48623804ff01ed7e1d8b/macaroni-0.0.3.tar.gz" } ] }