This commit is contained in:
Vincent Jacques
2012-02-22 07:57:29 +01:00
parent 0d52a449cc
commit b27529abb9
+19 -13
View File
@@ -137,31 +137,37 @@ class Creatable:
def apply( self, list, cls ):
self.__type = list.type
self.__attributeName = list.attributeName
cls._addMethod( self.__createName, self.__executeCreate )
cls._addMethod( self.__createName, self.__execute )
def __executeCreate( self, obj, *args, **kwds ):
def __execute( self, obj, *args, **kwds ):
data = self.__createArgumentsChecker.check( args, kwds )
return self.__type( obj._github, obj._github._dataRequest( "POST", obj._baseUrl + "/" + self.__attributeName, None, data ), lazy = True )
class ListGetable:
def apply( self, list, cls ):
self.__type = list.type
self.__attributeName = list.attributeName
cls._addMethod( "get_" + list.attributeName, self.__execute )
def __execute( self, obj ):
return [
self.__type( obj._github, attributes, lazy = True )
for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName, None, None )
]
### @todo Merge ObjectGetter in ListOfObjects, with a SingleGettable similar to Creatable
### @todo Add a ListGetable that couls be False for non-getable lists (repo/git/commits for example)
class ListOfObjects:
def __init__( self, attributeName, type, creatable = None ):
def __init__( self, attributeName, type, *capacities ):
self.attributeName = attributeName
self.type = type
self.__getName = "get_" + attributeName
self.creatable = creatable
self.__capacities = list( capacities )
self.__capacities.append( ListGetable() )
def apply( self, cls ):
cls._addMethod( self.__getName, self.__executeGet )
if self.creatable:
self.creatable.apply( self, cls )
def __executeGet( self, obj ):
return [
self.type( obj._github, attributes, lazy = True )
for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.attributeName, None, None )
]
for capacity in self.__capacities:
capacity.apply( self, cls )
class MethodFromCallable:
def __init__( self, name, callable ):