diff options
Diffstat (limited to 'lib/git/utils.py')
-rw-r--r-- | lib/git/utils.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/git/utils.py b/lib/git/utils.py index 39994bd5..96ec15b9 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -27,6 +27,12 @@ def is_git_dir(d): class LazyMixin(object): + """ + Base class providing an interface to lazily retrieve attribute values upon + first access. If slots are used, memory will only be reserved once the attribute + is actually accessed and retrieved the first time. All future accesses will + return the cached value as stored in the Instance's dict or slot. + """ __slots__ = tuple() def __getattr__(self, attr): @@ -49,3 +55,35 @@ class LazyMixin(object): in the single attribute.""" pass + +class Iterable(object): + """ + Defines an interface for iterable items which is to assure a uniform + way to retrieve and iterate items within the git repository + """ + __slots__ = tuple() + + @classmethod + def list_items(cls, repo, *args, **kwargs): + """ + Find all items of this type - subclasses can specify args and kwargs differently. + If no args are given, subclasses are obliged to return all items if no additional + arguments arg given. + + Note: Favor the iter_items method as it will + + Returns: + list(Item,...) list of item instances + """ + return list(cls.iter_items, repo, *args, **kwargs) + + + @classmethod + def iter_items(cls, repo, *args, **kwargs): + """ + For more information about the arguments, see find_all + Return: + iterator yielding Items + """ + raise NotImplementedError("To be implemented by Subclass") + |