Commits

Bryan Fink  committed ea1da74

enable use of Javascript as bucket linkfun by transforming {Bucket,Tag} map-fun-argument into json {bucket:Bucket,tag:Tag}

  • Participants
  • Parent commits 4fb1598

Comments (0)

Files changed (1)

File apps/riak/src/riak_mapper.erl

         {MapVal, NewMapState} = case FunTerm of
                                     {qfun, F} -> {(F)(V,KeyData,Arg), MapState};
                                     {jsfun, F} ->
-                                        {Retval, _} = riak_js:invoke_map(JsCtx, CSums, [jsonify_object(V), KeyData, Arg],
+                                        {Retval, _} = riak_js:invoke_map(JsCtx, CSums, [jsonify_object(V), KeyData, jsonify_arg(Arg)],
                                                                          <<"Riak">>, F, undefined),
                                         {Retval, MapState};
                                     {jsanon, {Bucket, Key}} ->
                                         exec_map(V, MapState, {jsanon, riak_js:fetch_fun(Bucket, Key)}, Arg, BKey, KeyData, VNode);
                                     {jsanon, F} ->
-                                        {Retval, NewCSums} = riak_js:invoke_map(JsCtx, CSums, [jsonify_object(V), KeyData, Arg],
+                                        {Retval, NewCSums} = riak_js:invoke_map(JsCtx, CSums, [jsonify_object(V), KeyData, jsonify_arg(Arg)],
                                                                                 undefined, <<"riakMapper">>, F),
                                         {Retval, MapState#jsenv{csums=NewCSums}};
                                     {modfun, M, F} ->
                    {Name, Value}
            end,
     lists:map(MDJS, dict:to_list(MD)).
+
+jsonify_arg({Bucket,Tag}) when (Bucket == '_' orelse is_binary(Bucket)),
+                               (Tag == '_' orelse is_binary(Tag)) ->
+    %% convert link match syntax
+    [{<<"bucket">>,Bucket},
+     {<<"tag">>,Tag}];
+jsonify_arg(Other) ->
+    Other.