mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Refactor
This commit is contained in:
+19
-13
@@ -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 ):
|
||||
|
||||
Reference in New Issue
Block a user