fixed http://groups.google.com/group/git-python/browse_thread/thread/62b972d2345c74c2...
[jelmer/gitpython.git] / lib / git / method_missing.py
1 class MethodMissingMixin(object):
2     """
3     A Mixin' to implement the 'method_missing' Ruby-like protocol.
4
5     This was `taken from a blog post <http://blog.iffy.us/?p=43>`_
6     """
7     def __getattr__(self, attr):
8         class MethodMissing(object):
9             def __init__(self, wrapped, method):
10                 self.__wrapped__ = wrapped
11                 self.__method__ = method
12             def __call__(self, *args, **kwargs):
13                 return self.__wrapped__.method_missing(self.__method__, *args, **kwargs)
14         return MethodMissing(self, attr)
15
16     def method_missing(self, *args, **kwargs):
17         """ This method should be overridden in the derived class. """
18         raise NotImplementedError(str(self.__wrapped__) + " 'method_missing' method has not been implemented.")