1 |
|
%% Copyright (c) 2022 Peter Morgan <peter.james.morgan@gmail.com> |
2 |
|
%% |
3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
|
%% you may not use this file except in compliance with the License. |
5 |
|
%% You may obtain a copy of the License at |
6 |
|
%% |
7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
8 |
|
%% |
9 |
|
%% Unless required by applicable law or agreed to in writing, software |
10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
|
%% See the License for the specific language governing permissions and |
13 |
|
%% limitations under the License. |
14 |
|
|
15 |
|
|
16 |
|
-module(pgec_util). |
17 |
|
|
18 |
|
|
19 |
|
-export([application_name/0]). |
20 |
|
-export([db/0]). |
21 |
|
-export([scope/0]). |
22 |
|
-export([snake_case/1]). |
23 |
|
-export([tl_snake_case/1]). |
24 |
|
|
25 |
|
|
26 |
|
snake_case([_ | _] = Labels) -> |
27 |
32 |
list_to_atom(lists:concat(lists:join("_", Labels))). |
28 |
|
|
29 |
|
|
30 |
|
split_on_snake_case(Name) -> |
31 |
32 |
string:split(atom_to_list(Name), "_"). |
32 |
|
|
33 |
|
tl_snake_case(Name) -> |
34 |
32 |
case split_on_snake_case(Name) of |
35 |
|
[_] -> |
36 |
:-( |
Name; |
37 |
|
|
38 |
|
Names -> |
39 |
32 |
snake_case(tl(Names)) |
40 |
|
end. |
41 |
|
|
42 |
|
|
43 |
|
scope() -> |
44 |
16 |
#{scope := Scope} = db(), |
45 |
16 |
Scope. |
46 |
|
|
47 |
|
|
48 |
|
application_name() -> |
49 |
:-( |
#{application_name := ApplicationName} = db(), |
50 |
:-( |
ApplicationName. |
51 |
|
|
52 |
|
|
53 |
|
db() -> |
54 |
112 |
?FUNCTION_NAME(maps:next(maps:iterator(pgmp_dbs:all()))). |
55 |
|
|
56 |
|
db({_, Configuration, _}) -> |
57 |
112 |
Configuration. |