You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/08/12 17:54:09 UTC
[09/13] couch commit: updated refs/heads/master to 311ba94
Add couch_db_plugin:after_doc_read/2
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/4f6db4a7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/4f6db4a7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/4f6db4a7
Branch: refs/heads/master
Commit: 4f6db4a774d3274ee5d330bfe785de36a3c2b7e8
Parents: 1edf06c
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Fri Jun 19 10:47:05 2015 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Aug 11 12:24:59 2015 -0700
----------------------------------------------------------------------
src/couch_db.erl | 8 +++-----
src/couch_db_plugin.erl | 9 ++++++++-
test/couch_db_plugin_tests.erl | 29 +++++++++++++++++++++++++++--
3 files changed, 38 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4f6db4a7/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index a693fa2..e84898b 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -1399,11 +1399,9 @@ make_doc(#db{fd=Fd}=Db, Id, Deleted, Bp, RevisionPath) ->
after_doc_read(Db, Doc).
-after_doc_read(#db{after_doc_read = nil}, Doc) ->
- Doc;
-after_doc_read(#db{after_doc_read = Fun} = Db, Doc) ->
- Fun(couch_doc:with_ejson_body(Doc), Db).
-
+after_doc_read(#db{} = Db, Doc) ->
+ DocWithBody = couch_doc:with_ejson_body(Doc),
+ couch_db_plugin:after_doc_read(Db, DocWithBody).
increment_stat(#db{options = Options}, Stat) ->
case lists:member(sys_db, Options) of
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4f6db4a7/src/couch_db_plugin.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_plugin.erl b/src/couch_db_plugin.erl
index 4e08aa2..88e37c3 100644
--- a/src/couch_db_plugin.erl
+++ b/src/couch_db_plugin.erl
@@ -14,7 +14,8 @@
-export([
validate_dbname/2,
- before_doc_update/2
+ before_doc_update/2,
+ after_doc_read/2
]).
-define(SERVICE_ID, couch_db).
@@ -37,6 +38,12 @@ before_doc_update(#db{before_doc_update = Fun} = Db, Doc0) ->
[Doc1, _Db] -> Doc1
end.
+after_doc_read(#db{after_doc_read = Fun} = Db, Doc0) ->
+ case with_pipe(after_doc_read, [Doc0, Db]) of
+ [Doc1, _Db] when is_function(Fun) -> Fun(Doc1, Db);
+ [Doc1, _Db] -> Doc1
+ end.
+
%% ------------------------------------------------------------------
%% Internal Function Definitions
%% ------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4f6db4a7/test/couch_db_plugin_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_db_plugin_tests.erl b/test/couch_db_plugin_tests.erl
index c26ea4d..06a2360 100644
--- a/test/couch_db_plugin_tests.erl
+++ b/test/couch_db_plugin_tests.erl
@@ -14,7 +14,8 @@
-export([
validate_dbname/2,
- before_doc_update/2
+ before_doc_update/2,
+ after_doc_read/2
]).
-include_lib("couch/include/couch_eunit.hrl").
@@ -45,6 +46,10 @@ before_doc_update({fail, _Doc}, _Db) -> throw(before_doc_update);
before_doc_update({true, Doc}, Db) -> [{true, [before_doc_update|Doc]}, Db];
before_doc_update({false, Doc}, Db) -> [{false, Doc}, Db].
+after_doc_read({fail, _Doc}, _Db) -> throw(after_doc_read);
+after_doc_read({true, Doc}, Db) -> [{true, [after_doc_read|Doc]}, Db];
+after_doc_read({false, Doc}, Db) -> [{false, Doc}, Db].
+
callback_test_() ->
{
"callback tests",
@@ -57,7 +62,11 @@ callback_test_() ->
fun before_doc_update_match/0,
fun before_doc_update_no_match/0,
- fun before_doc_update_throw/0
+ fun before_doc_update_throw/0,
+
+ fun after_doc_read_match/0,
+ fun after_doc_read_no_match/0,
+ fun after_doc_read_throw/0
]
}
}.
@@ -92,3 +101,19 @@ before_doc_update_throw() ->
?_assertThrow(
before_doc_update,
couch_db_plugin:before_doc_update(#db{}, {fail, [doc]})).
+
+
+after_doc_read_match() ->
+ ?_assertMatch(
+ {true, [after_doc_read, doc]},
+ couch_db_plugin:after_doc_read(#db{}, {true, [doc]})).
+
+after_doc_read_no_match() ->
+ ?_assertMatch(
+ {false, [doc]},
+ couch_db_plugin:after_doc_read(#db{}, {false, [doc]})).
+
+after_doc_read_throw() ->
+ ?_assertThrow(
+ after_doc_read,
+ couch_db_plugin:after_doc_read(#db{}, {fail, [doc]})).