Last updated:
0 purchases
asagglib 0.1.1
Asagg
The Asagg library (Auto Setter And Getter Generator) is a library inspired by another
library that is in the Java environment, which is the Lombock library, this library
aims to automate the generation of access methods to private attributes,
automatically generating Getters and Setters Among other things.
Installation
To install the library use the following command, you can also use another
dependency manager of your choice, such as Poetry or
Pipenv.
# for pip
> pip install asagg-lib
# for Poetry
> poetry add --group=dev asagg-lib
# for Pipenv
> pipenv install asagg-lib
Usage
Following the same line of operation as Lombock, to be able to use the library, just
use a decorator and the magic will happen. The decorators are divided into three functions
where each one has a functionality and one has the functionality of the other two,
being their combination.
Old way to create properties without Asagg:
class MyClass:
def __init__(self):
self._my_private_attribute = "private"
@property
def my_private_attribute(self):
return self._my_private_attribute
my_class = MyClass()
# method generated automaticly with Asagg
print(my_class.my_private_attribute) # Output: "private"
New way to create properties with Asagg:
from asagg_lib import Asagg
@Asagg.getter
class MyClass:
def __init__(self):
self._my_private_attribute = "private"
my_class = MyClass()
# method generated automaticly with Asagg
print(my_class.my_private_attribute) # Output: "private"
Asagg.getter
This decorator is responsible for generating the getters of the class to which it is applied,
it will scan the attributes of the class and take only the private and protected attributes,
then a function will be applied to generate a property for each attribute collected
and thus making the getters available
Example:
from asagg_lib import Asagg
@Asagg.getter
class MyClass:
def __init__(self):
self._my_private_attribute = "private"
Asagg.setter
This decorator is responsible for generating the setters of the class to which it is applied,
it will scan the attributes of the class and take only the private and protected attributes,
then a function will be applied to generate a property for each attribute collected
and thus making the setters available
Example:
from asagg_lib import Asagg
@Asagg.setter
class MyClass:
def __init__(self):
self._my_private_attribute = "private"
📘 Info
The function used to generate the setters also uses a typing
check to prevent a value of a different type from being assigned to the property
Asagg.data
This decorator is responsible for generating the setters and getters of the class to which
it is applied, it will scan the attributes of the class and take only the private
and protected attributes, then a function will be applied to generate a property
for each attribute collected and thus making the setters and getters available
Example:
from asagg_lib import Asagg
@Asagg.data
class MyClass:
def __init__(self):
self._my_private_attribute = "private"
All rights reserved © [email protected]
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.