From 8753798e196898e087bc2b33b15486aafc0e7363 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 21 Feb 2012 23:24:24 +0100 Subject: Add docstrings. --- src/eu/mulk/instadump.clj | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/eu/mulk/instadump.clj b/src/eu/mulk/instadump.clj index fffc29e..704b37b 100644 --- a/src/eu/mulk/instadump.clj +++ b/src/eu/mulk/instadump.clj @@ -71,10 +71,17 @@ ;;;; * Public API -(defn setup-instadump! [dirname] +(defn setup-instadump! + "Set up the Instadump database at the file system location indicated + by dirname." + [dirname] (reset! dbenv (make-db-env dirname))) -(defmacro defstate [sym default] +(defmacro defstate + "Define a global ref managed by Instadump. The supplied default + value is used if the variable cannot be found in the database. + Otherwise, the value stored in the database is used." + [sym default] (let [dbkey (str *ns* "/" (name sym))] `(defonce ~sym (let [r# (ref (with-db (getkey ~dbkey ~default)))] @@ -82,13 +89,22 @@ r#)))) -(defn save-all-global-state! [] +(defn save-all-global-state! + "Direct Instadump to dump a snapshot of all variables created by + defstate into the database. save-all-global-state! runs in an + implicit transaction in order to ensure data consistency." + [] (with-db (dosync (doseq [[key r] @state-vars] (putkey key (ensure r)))))) -(defn reload-all-global-state! [] +(defn reload-all-global-state! + "Direct Instadump to revert all variables created by defstate to the + state saved by the last invocation of save-all-global-state!. Will + fail if any variables cannot be restored (e.g. if some variables + have never been saved before)." + [] (with-db (dosync (doseq [[key r] @state-vars] -- cgit v1.2.3