mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-22 19:14:20 +00:00
✨ Add get method to Scrolls
This commit is contained in:
parent
164d31ee92
commit
d91d9d6e04
3 changed files with 10 additions and 2 deletions
|
@ -9,7 +9,7 @@ It may be incomplete or outdated, as it is automatically updated.
|
|||
:maxdepth: 3
|
||||
|
||||
alchemist
|
||||
baron
|
||||
campaigns
|
||||
lazy
|
||||
scrolls
|
||||
typing
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from __future__ import annotations
|
||||
from royalnet.typing import *
|
||||
import functools
|
||||
|
||||
|
||||
Result = TypeVar("Result")
|
||||
|
|
|
@ -13,6 +13,9 @@ import json
|
|||
from .exc import *
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class Scroll:
|
||||
"""
|
||||
A configuration handler that allows getting values from both the environment variables and a config file.
|
||||
|
@ -127,6 +130,12 @@ class Scroll:
|
|||
except NotFoundError:
|
||||
return self._get_from_config(item)
|
||||
|
||||
def get(self, item: str, default: T) -> Union[JSONScalar, T]:
|
||||
try:
|
||||
return self[item]
|
||||
except NotFoundError:
|
||||
return default
|
||||
|
||||
|
||||
Scroll.loaders = {
|
||||
".json": Scroll.from_json,
|
||||
|
|
Loading…
Reference in a new issue