Pyruler API¶
Submodules¶
pyruler.pyruler module¶
Ruler definitions.
- class pyruler.pyruler.Rule(name: AnyStr, resolver: Callable)¶
Bases:
objectDefinition for atomic operation that validates data.
- Parameters
name – Name of the rule
resolver – Callable function that receives exactly 1 param as the data that will be validated
- execute(data: Any) → bool¶
Execute rule validation.
- Parameters
data –
- property name¶
Return the name of the rule.
- Return AnyStr
Rule name
- class pyruler.pyruler.RuleSet(name: AnyStr)¶
Bases:
objectRule Set definition to apply a set of rules to a context info.
- Parameters
name – Identifier name of the rule set
- add_many(rules: Iterable[pyruler.pyruler.Rule]) → None¶
Add many rules at ones.
- Parameters
rules – Iterable object of rules
- add_rule(rule: pyruler.pyruler.Rule) → NoReturn¶
Add new role to the set.
- Parameters
rule – New Rule object to be applied by the set
- Raises
RuleSetConfigError – when the set detects that the provided rule was already added to the set
- apply(data: Any, fail_fast: Optional[bool] = True) → NoReturn¶
Apply the configured rule set to a specific data.
- Parameters
data – Data to be validated by the rule set
fail_fast – flag to determine if the error will raise at first not True rule, or will execute all and collect all the rules that fails with the data before raise it.
- Raises
RuleError – when the data is not complaint with some rule of the set
- count_rules() → int¶
Count the total of rules configured on the set.
- Return int
Count of rules
- property name¶
Get property value.
- rule_names() → List¶
Return a list with the names of all the configured rules of the set.
- Return List[AnyStr]
List of rule names
- class pyruler.pyruler.Ruler¶
Bases:
objectStore RuleSet objects to be applied over a given data. This class can apply one single stored RuleSet, a list of of some of the configured RuleSet objects or all of them.
- add_many(rule_sets: Iterable[pyruler.pyruler.RuleSet]) → NoReturn¶
Add many RuleSet objects at ones.
- Parameters
rule_sets – Iterable object of rule sets to be added
- add_set(rule_set: pyruler.pyruler.RuleSet) → NoReturn¶
Add a new Rule set to the ruler.
- Parameters
rule_set – configured rule set object
- Raises
RulerConfigError – When the ruler detects that the provided rule_set was already configured
- apply(data: Any, sets: Optional[Union[AnyStr, Tuple, List, Set]] = None, fail_fast: Optional[bool] = True) → NoReturn¶
Apply specified rule set, all of the stored sets or a sub collection of the stored rule sets.
- Parameters
sets – Rule sets to be applied
data – Data to be validated by the rule sets
fail_fast – Run on fail fast mode
- Raises
RuleError – When some rule was not asserted successfully by the rule set
RulerError – When some set can’t be applied
- count_sets() → int¶
Count the total of configured sets.
- Return int
Count of sets
- rule_set_names() → List¶
Return a list of all configured RuleSet objects in the ruler.
- Returns
List of rule set names
pyruler.errors module¶
Custom ruler errors.
- exception pyruler.errors.RuleError¶
Bases:
ExceptionBase Rule error.
- exception pyruler.errors.RuleSetConfigError¶
Bases:
ExceptionBase error for RuleSet configuration.
- exception pyruler.errors.RuleSetError¶
Bases:
ExceptionBase RuleSet error.
- exception pyruler.errors.RulerConfigError¶
Bases:
ExceptionBase error for Ruler configuration.
- exception pyruler.errors.RulerError¶
Bases:
ExceptionBase Ruler error.
pyruler.linked_list module¶
Custom creation of a LinkedList.
- class pyruler.linked_list.LinkedList(values: Optional[Iterable[pyruler.linked_list.T]] = None)¶
Bases:
Generic[pyruler.linked_list.T],Sized,Iterable,abc.ABCCustom LinkedList class.
- add(value: pyruler.linked_list.T) → NoReturn¶
This is an alias for add_last method. :param value: Value to be added at the end of the list
- add_first(value: pyruler.linked_list.T) → NoReturn¶
Add new node at the beginning of the list.
- add_last(value: pyruler.linked_list.T) → NoReturn¶
Add new node at the end of the list. :param value: New list value
- add_many(values: Iterable[pyruler.linked_list.T]) → NoReturn¶
Add many items to the list at ones with the add_last method. :param values: Iterable object with values to be added to the LinkedList
- empty() → bool¶
Return a boolean assertion if the list is empty. :return bool: Assertion
- first() → pyruler.linked_list.T¶
Return first element of the list. :return T: First element value
- last() → pyruler.linked_list.T¶
return the last element of the list :return T: Last element value
- class pyruler.linked_list.ListNode(value: Any)¶
Bases:
objectSingle list node class.
Module contents¶
Export resources.