fix(tpl): rename `trivial` -> `is_const`
This is clearer. Former naming was a bit misleading.
This commit is contained in:
parent
7bb995f0c6
commit
a9693eada7
|
@ -184,7 +184,7 @@ compile_topic({eq, Topic}) ->
|
|||
{eq, emqx_topic:words(bin(Topic))};
|
||||
compile_topic(Topic) ->
|
||||
Template = emqx_authz_utils:parse_str(Topic, [?VAR_USERNAME, ?VAR_CLIENTID]),
|
||||
case emqx_connector_template:trivial(Template) of
|
||||
case emqx_connector_template:is_const(Template) of
|
||||
true -> emqx_topic:words(bin(Topic));
|
||||
false -> {pattern, Template}
|
||||
end.
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
-export([parse_deep/1]).
|
||||
-export([parse_deep/2]).
|
||||
-export([validate/2]).
|
||||
-export([trivial/1]).
|
||||
-export([is_const/1]).
|
||||
-export([unparse/1]).
|
||||
-export([render/2]).
|
||||
-export([render/3]).
|
||||
|
@ -124,7 +124,6 @@ parse_accessor(Var) ->
|
|||
[<<>>] ->
|
||||
?PH_VAR_THIS;
|
||||
Name ->
|
||||
% TODO: lowercase?
|
||||
Name
|
||||
end.
|
||||
|
||||
|
@ -140,9 +139,11 @@ validate(Allowed, Template) ->
|
|||
{error, [{Var, disallowed} || Var <- Disallowed]}
|
||||
end.
|
||||
|
||||
-spec trivial(t()) ->
|
||||
%% @doc Check if a template is constant with respect to rendering, i.e. does not
|
||||
%% contain any placeholders.
|
||||
-spec is_const(t()) ->
|
||||
boolean().
|
||||
trivial(Template) ->
|
||||
is_const(Template) ->
|
||||
validate([], Template) == ok.
|
||||
|
||||
-spec unparse(t()) ->
|
||||
|
|
|
@ -122,18 +122,18 @@ t_unparse(_) ->
|
|||
unicode:characters_to_binary(emqx_connector_template:unparse(Template))
|
||||
).
|
||||
|
||||
t_trivial(_) ->
|
||||
t_const(_) ->
|
||||
?assertEqual(
|
||||
true,
|
||||
emqx_connector_template:trivial(emqx_connector_template:parse(<<"">>))
|
||||
emqx_connector_template:is_const(emqx_connector_template:parse(<<"">>))
|
||||
),
|
||||
?assertEqual(
|
||||
false,
|
||||
emqx_connector_template:trivial(emqx_connector_template:parse(<<"a:${a},b:${b},c:$${c}">>))
|
||||
emqx_connector_template:is_const(emqx_connector_template:parse(<<"a:${a},b:${b},c:$${c}">>))
|
||||
),
|
||||
?assertEqual(
|
||||
true,
|
||||
emqx_connector_template:trivial(
|
||||
emqx_connector_template:is_const(
|
||||
emqx_connector_template:parse(<<"a:$${a},b:$${b},c:$${c}">>)
|
||||
)
|
||||
).
|
||||
|
|
Loading…
Reference in New Issue