diff options
Diffstat (limited to 'src/mango/src/mango_opts.erl')
-rw-r--r-- | src/mango/src/mango_opts.erl | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/mango/src/mango_opts.erl b/src/mango/src/mango_opts.erl index 92c07f743..04fe5bbf8 100644 --- a/src/mango/src/mango_opts.erl +++ b/src/mango/src/mango_opts.erl @@ -39,10 +39,8 @@ default_limit/0 ]). - -include("mango.hrl"). - validate_idx_create({Props}) -> Opts = [ {<<"index">>, [ @@ -81,7 +79,6 @@ validate_idx_create({Props}) -> ], validate(Props, Opts). - validate_find({Props}) -> Opts = [ {<<"selector">>, [ @@ -169,7 +166,6 @@ validate_find({Props}) -> ], validate(Props, Opts). - validate_bulk_delete({Props}) -> Opts = [ {<<"docids">>, [ @@ -185,7 +181,6 @@ validate_bulk_delete({Props}) -> ], validate(Props, Opts). - validate(Props, Opts) -> case mango_util:assert_ejson({Props}) of true -> @@ -202,13 +197,11 @@ validate(Props, Opts) -> end, {ok, Acc}. - is_string(Val) when is_binary(Val) -> {ok, Val}; is_string(Else) -> ?MANGO_ERROR({invalid_string, Else}). - is_boolean(true) -> {ok, true}; is_boolean(false) -> @@ -216,19 +209,16 @@ is_boolean(false) -> is_boolean(Else) -> ?MANGO_ERROR({invalid_boolean, Else}). - is_pos_integer(V) when is_integer(V), V > 0 -> {ok, V}; is_pos_integer(Else) -> ?MANGO_ERROR({invalid_pos_integer, Else}). - is_non_neg_integer(V) when is_integer(V), V >= 0 -> {ok, V}; is_non_neg_integer(Else) -> ?MANGO_ERROR({invalid_non_neg_integer, Else}). - is_object({Props}) -> true = mango_util:assert_ejson({Props}), {ok, {Props}}; @@ -236,27 +226,26 @@ is_object(Else) -> ?MANGO_ERROR({invalid_object, Else}). is_ok_or_false(<<"ok">>) -> - {ok, ok}; -is_ok_or_false(<<"false">>) -> % convenience - {ok, false}; + {ok, ok}; +% convenience +is_ok_or_false(<<"false">>) -> + {ok, false}; is_ok_or_false(false) -> - {ok, false}; + {ok, false}; is_ok_or_false(Else) -> - ?MANGO_ERROR({invalid_ok_or_false_value, Else}). + ?MANGO_ERROR({invalid_ok_or_false_value, Else}). validate_idx_name(auto_name) -> {ok, auto_name}; validate_idx_name(Else) -> is_string(Else). - validate_selector({Props}) -> Norm = mango_selector:normalize({Props}), {ok, Norm}; validate_selector(Else) -> ?MANGO_ERROR({invalid_selector_json, Else}). - %% We re-use validate_use_index to make sure the index names are valid validate_bulk_docs(Docs) when is_list(Docs) -> lists:foreach(fun validate_use_index/1, Docs), @@ -264,7 +253,6 @@ validate_bulk_docs(Docs) when is_list(Docs) -> validate_bulk_docs(Else) -> ?MANGO_ERROR({invalid_bulk_docs, Else}). - validate_use_index(IndexName) when is_binary(IndexName) -> case binary:split(IndexName, <<"/">>) of [DesignId] -> @@ -284,13 +272,13 @@ validate_use_index([]) -> {ok, []}; validate_use_index([DesignId]) when is_binary(DesignId) -> {ok, [DesignId]}; -validate_use_index([DesignId, ViewName]) - when is_binary(DesignId), is_binary(ViewName) -> +validate_use_index([DesignId, ViewName]) when + is_binary(DesignId), is_binary(ViewName) +-> {ok, [DesignId, ViewName]}; validate_use_index(Else) -> ?MANGO_ERROR({invalid_index_name, Else}). - validate_bookmark(null) -> {ok, nil}; validate_bookmark(<<>>) -> @@ -300,15 +288,12 @@ validate_bookmark(Bin) when is_binary(Bin) -> validate_bookmark(Else) -> ?MANGO_ERROR({invalid_bookmark, Else}). - validate_sort(Value) -> mango_sort:new(Value). - validate_fields(Value) -> mango_fields:new(Value). - validate_partitioned(true) -> {ok, true}; validate_partitioned(false) -> @@ -318,14 +303,12 @@ validate_partitioned(db_default) -> validate_partitioned(Else) -> ?MANGO_ERROR({invalid_partitioned_value, Else}). - validate_partition(<<>>) -> {ok, <<>>}; validate_partition(Partition) -> couch_partition:validate_partition(Partition), {ok, Partition}. - validate_opts([], Props, Acc) -> {Props, lists:reverse(Acc)}; validate_opts([{Name, Desc} | Rest], Props, Acc) -> @@ -339,7 +322,6 @@ validate_opts([{Name, Desc} | Rest], Props, Acc) -> validate_opts(Rest, Props, NewAcc) end. - validate_opt(_Name, [], Value) -> Value; validate_opt(Name, Desc0, undefined) -> @@ -372,6 +354,5 @@ validate_opt(Name, [{validator, Fun} | Rest], Value) -> ?MANGO_ERROR({invalid_value, Name, Value}) end. - default_limit() -> config:get_integer("mango", "default_limit", 25). |