Namdak Tonpa 5 years ago
parent
commit
108577f99a
3 changed files with 9 additions and 4 deletions
  1. 2 2
      mix.exs
  2. 6 2
      src/rest.erl
  3. 1 0
      src/rest_kvs.erl

+ 2 - 2
mix.exs

@@ -3,7 +3,7 @@ defmodule REST.Mixfile do
 
   def project do
     [app: :rest,
-     version: "5.10.2",
+     version: "5.10.3",
      description: "REST erlang interface generator",
      deps: deps(),
      package: package()]
@@ -19,7 +19,7 @@ defmodule REST.Mixfile do
   def deps, do: [ {:ex_doc, ">= 0.0.0", only: :dev},
                   {:rocksdb, "~> 1.3.2"},
                   {:syn, "~> 1.6.3"},
-                  {:erp, "~> 0.10.1"},
+                  {:erp, "~> 0.10.2"},
                   {:n2o, "~> 6.9.0"},
                   {:jsone, "~> 1.5.0"},
                   {:cowboy, "~> 2.5.0"} ]

+ 6 - 2
src/rest.erl

@@ -145,13 +145,15 @@ props_skip({<<BinaryKey/binary>>, Value}, Acc) ->
     catch _:_ -> Acc end;
 props_skip({Key, Value}, Acc) -> [{Key, from_json(Value)} | Acc].
 
+to_json(X) when is_tuple(X) -> Module = hd(tuple_to_list(X)), Module:to_json(X);
 to_json(Data) ->
     case is_string(Data) of
         true  -> rest:to_binary(Data);
         false -> json_match(Data)
     end.
 
-json_match([{_, _} | _] = Props) -> [{rest:to_binary(Key), to_json(Value)} || {Key, Value} <- Props];
+json_match([{_, _} | _] = Props) ->
+  [ {rest:to_binary(Key), to_json(Value)} || {Key, Value} <- Props];
 json_match([_ | _] = NonEmptyList) -> [to_json(X) || X <- NonEmptyList];
 json_match(Any) -> Any.
 
@@ -164,4 +166,6 @@ to_binary(A) when is_atom(A) -> atom_to_binary(A,latin1);
 to_binary(B) when is_binary(B) -> B;
 to_binary(I) when is_integer(I) -> to_binary(integer_to_list(I));
 to_binary(F) when is_float(F) -> float_to_binary(F,[{decimals,9},compact]);
-to_binary(L) when is_list(L) ->  iolist_to_binary(L).
+to_binary(L) when is_list(L) ->  iolist_to_binary(L);
+to_binary({money,_,_}) -> <<"money">>.
+

+ 1 - 0
src/rest_kvs.erl

@@ -63,6 +63,7 @@ to_json(#{bindings := #{resource := Module, id := Id}} = Req, State) ->
     {iolist_to_binary(?REST_JSON:encode(Type:to_json(Resource))), Req, State};
 to_json(#{bindings := #{resource := Module}} = Req, State) ->
     Fold = [ begin M = element(1,Resource), M:to_json(Resource) end || Resource <- kvs:all(c(Module))],
+    io:format("DEBUG: ~p",[{Module,Fold}]),
     {iolist_to_binary(?REST_JSON:encode([{Module,Fold}])), Req, State}.
 
 content_types_accepted(Req, State) ->