Skip to content

Commit d469204

Browse files
Merge pull request #8 from MurdoMaclachlan/dev
Add is_scope() method
2 parents 7843d50 + 1a291ac commit d469204

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

smooth_logger/Logger.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ def init_bar(self, limit: int) -> None:
254254
self.bar = ProgressBar(limit=limit)
255255
self.bar.open()
256256

257+
def is_scope(self, scope: str, category: Categories = None) -> bool:
258+
"""
259+
Queries a given scope to check if it exists, and optionally if it matches a given category.
260+
261+
If no category is given, will return true if the scope exists. If a category is given, will
262+
return true if and only if the scope exists and matches the given category.
263+
264+
:param scope: the scope to check
265+
:param category: optional; the category to check for
266+
:return: whether the scope exists and optionally matches the category
267+
"""
268+
scope_exists: bool = scope in self._scopes
269+
if category is None:
270+
return scope_exists
271+
else:
272+
return scope_exists and self._scopes[scope] == category
273+
257274
def new(self,
258275
message: str,
259276
scope: str,

0 commit comments

Comments
 (0)