Skip to content

Commit adf7b99

Browse files
author
Simon MacMullen
committed
Refactor.
1 parent e62c7e8 commit adf7b99

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/rabbit_runtime_parameters.erl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ list(VHost) -> list(VHost, '_').
140140
list_component(Component) -> list('_', Component).
141141

142142
list(VHost, Component) ->
143-
assert_vhost(VHost),
143+
rabbit_vhost:assert(VHost),
144144
Match = #runtime_parameters{key = {VHost, Component, '_'}, _ = '_'},
145145
[p(P) || #runtime_parameters{key = {_VHost, Comp, _Name}} = P <-
146146
mnesia:dirty_match_object(?TABLE, Match),
@@ -149,12 +149,6 @@ list(VHost, Component) ->
149149
list_formatted(VHost) ->
150150
[pset(value, format(pget(value, P)), P) || P <- list(VHost)].
151151

152-
assert_vhost('_') -> ok;
153-
assert_vhost(VHost) -> case rabbit_vhost:exists(VHost) of
154-
true -> ok;
155-
false -> throw({error, {no_such_vhost, VHost}})
156-
end.
157-
158152
lookup(VHost, Component, Name) ->
159153
case lookup0(VHost, Component, Name, rabbit_misc:const(not_found)) of
160154
not_found -> not_found;

src/rabbit_vhost.erl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
%%----------------------------------------------------------------------------
2222

23-
-export([add/1, delete/1, exists/1, list/0, with/2]).
23+
-export([add/1, delete/1, exists/1, list/0, with/2, assert/1]).
2424
-export([info/1, info/2, info_all/0, info_all/1]).
2525

2626
-ifdef(use_specs).
@@ -30,6 +30,7 @@
3030
-spec(exists/1 :: (rabbit_types:vhost()) -> boolean()).
3131
-spec(list/0 :: () -> [rabbit_types:vhost()]).
3232
-spec(with/2 :: (rabbit_types:vhost(), rabbit_misc:thunk(A)) -> A).
33+
-spec(assert/1 :: (rabbit_types:vhost()) -> 'ok').
3334

3435
-spec(info/1 :: (rabbit_types:vhost()) -> rabbit_types:infos()).
3536
-spec(info/2 :: (rabbit_types:vhost(), rabbit_types:info_keys())
@@ -120,6 +121,13 @@ with(VHostPath, Thunk) ->
120121
end
121122
end.
122123

124+
%% Like with/2 but outside an Mnesia tx
125+
assert('_') -> ok;
126+
assert(VHostPath) -> case rabbit_vhost:exists(VHostPath) of
127+
true -> ok;
128+
false -> throw({error, {no_such_vhost, VHostPath}})
129+
end.
130+
123131
%%----------------------------------------------------------------------------
124132

125133
infos(Items, X) -> [{Item, i(Item, X)} || Item <- Items].

0 commit comments

Comments
 (0)