Update docs

This commit is contained in:
vrde 2017-01-27 14:35:37 +01:00
parent 54544f66a0
commit 2c87f1c28a
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
2 changed files with 20 additions and 0 deletions

View File

@ -65,6 +65,11 @@ class MongoDBConnection(Connection):
def collection(name):
"""Return a lazy object that can be used to compose a query.
Args:
name (str): the name of the collection to query.
"""
return Lazy()[name]

View File

@ -160,8 +160,17 @@ def is_genesis_block(block):
class Lazy:
"""Lazy objects are useful to create chains of methods to
execute later.
A lazy object records the methods that has been called, and
replay them when the :py:meth:`run` method is called. Note that
:py:meth:`run` needs an object `instance` to replay all the
methods that have been recorded.
"""
def __init__(self):
"""Instantiate a new Lazy object."""
self.stack = []
def __getattr__(self, name):
@ -178,6 +187,12 @@ class Lazy:
return self
def run(self, instance):
"""Run the recorded chain of methods on `instance`.
Args:
instance: an object.
"""
last = instance
for item in self.stack: