From 2c87f1c28acd81ebc25e5688d70307ac6b034938 Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 27 Jan 2017 14:35:37 +0100 Subject: [PATCH] Update docs --- bigchaindb/backend/mongodb/connection.py | 5 +++++ bigchaindb/utils.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/bigchaindb/backend/mongodb/connection.py b/bigchaindb/backend/mongodb/connection.py index 61af4469..2be39194 100644 --- a/bigchaindb/backend/mongodb/connection.py +++ b/bigchaindb/backend/mongodb/connection.py @@ -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] diff --git a/bigchaindb/utils.py b/bigchaindb/utils.py index 6ceace6b..1860dd3e 100644 --- a/bigchaindb/utils.py +++ b/bigchaindb/utils.py @@ -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: