In the following code, Graph() is acting as a proxy to Vertex and Edge -- clients only access Vertex and Edge through Graph():
from rest import Resource
from elements import Vertex, Edge
class Graph(object):
def __init__(self,db_url):
self.resource = Resource(db_url)
self.vertices = Vertex
self.edges = Edge
g1 = Graph('http://localhost/one')
g2 = Graph('http://localhost/two')
What are the best ways for Vertex and Edge to access the resource object, without having to pass it as a param to Vertex and Edge?
One of the reasons I don't want to pass it as a param is because Vertex and Edge have classmethods, such as create(), that need access to the resource object too.
Flask/Werkzeug uses "context locals" (http://werkzeug.pocoo.org/docs/local/) -- is that the right approach here, or is there a better way?