-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement (de)serialization in rulesets
- Loading branch information
1 parent
9aaceaa
commit e4bc671
Showing
10 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
from attrs import define, field | ||
import uuid | ||
|
||
from attrs import Factory, define, field | ||
|
||
from griptape.mixins.serializable_mixin import SerializableMixin | ||
from griptape.rules import BaseRule, Ruleset | ||
|
||
|
||
@define(slots=False) | ||
class RuleMixin: | ||
class RuleMixin(SerializableMixin): | ||
DEFAULT_RULESET_NAME = "Default Ruleset" | ||
|
||
_rulesets: list[Ruleset] = field(factory=list, kw_only=True, alias="rulesets") | ||
_rulesets: list[Ruleset] = field(factory=list, kw_only=True, alias="rulesets", metadata={"serializable": True}) | ||
rules: list[BaseRule] = field(factory=list, kw_only=True) | ||
_default_ruleset_name: str = field(default=Factory(lambda: RuleMixin.DEFAULT_RULESET_NAME), kw_only=True) | ||
_default_ruleset_id: str = field(default=Factory(lambda: uuid.uuid4().hex), kw_only=True) | ||
|
||
@property | ||
def rulesets(self) -> list[Ruleset]: | ||
rulesets = self._rulesets.copy() | ||
|
||
if self.rules: | ||
rulesets.append(Ruleset(name=self.DEFAULT_RULESET_NAME, rules=self.rules)) | ||
rulesets.append(Ruleset(id=self._default_ruleset_id, name=self._default_ruleset_name, rules=self.rules)) | ||
|
||
return rulesets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters