|
6 | 6 | -compile(export_all). |
7 | 7 | -endif. |
8 | 8 |
|
9 | | --type limit() :: integer()|all. |
| 9 | +%-type limit() :: pos_integer()|all. |
10 | 10 | -type syntaxTree() :: erl_syntax:syntaxTree(). |
11 | | --type name() :: atom()|[byte()]. |
| 11 | +-type name() :: atom()|[byte(),...]. |
12 | 12 |
|
13 | 13 | -export([compile/1, compile/2, edoc_module/1, edoc_module/2, process_tokens/1, trick_out_forms/2]). |
14 | 14 | -spec compile(binary() | [atom() | [any()] | char()]) -> any(). |
|
34 | 34 | -spec save_forms(atom()) -> [{'tree',atom(),{'attr',_,[any()],{_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],{_,_,_}},_},...]. |
35 | 35 | -spec parameter_getter_forms([any()]) -> [{'tree',atom(),{_,_,_,_},_} | {'wrapper',atom(),{_,_,_,_},_}]. |
36 | 36 | -spec deep_get_forms() -> [{'tree',atom(),{'attr',_,[any()],{_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],{_,_,_}},_},...]. |
37 | | --spec get_attributes_forms(atom(),[any()]) -> [{'tree',atom(),{_,_,_,_},_} | {'wrapper',atom(),{_,_,_,_},_},...]. |
38 | | --spec set_attributes_forms(atom(),[any()]) -> [{'tree',atom(),{_,_,_,_},_} | {'wrapper',atom(),{_,_,_,_},_},...]. |
39 | | --spec association_forms(atom(),[any()]) -> [any(),...]. |
40 | | --spec belongs_to_list_forms([any()]) -> [{'tree',atom(),{_,_,_,_},_} | {'wrapper',atom(),{_,_,_,_},_},...]. |
41 | | --spec attribute_names_forms(atom() | string() | number(),[any()]) -> [{'tree',atom(),{_,_,_,_},_} | {'wrapper',atom(),{_,_,_,_},_},...]. |
42 | | --spec has_one_forms(atom() | string(),atom(),[any()]) -> [{'tree',atom(),{'attr',_,[any()],{_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],{_,_,_}},_},...]. |
43 | | --spec has_many_forms(atom(),atom(),limit()|many,[any()]) -> [{'tree',atom(),{'attr',_,[any()],{_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],{_,_,_}},_},...]. |
44 | | --spec first_or_undefined_forms({'tree',atom(),{'attr',0,[],'none'},_}) -> {'tree',atom(),{'attr',0,[],'none'},_}. |
45 | | --spec has_many_query_forms(atom() | string()) -> {'tree',atom(),{'attr',0,[],'none'},_}. |
46 | | --spec has_many_query_forms_with_conditions(atom() | string()) -> {'tree',atom(),{'attr',_,[any()],'none' | {_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],'none' | {_,_,_}},_}. |
47 | | -%-spec has_many_application_forms(atom() | string(), |
48 | | -% {'tree',atom(),{'attr',_,[any()],'none' | {_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],'none' | {_,_,_}},_},,atom() | string(),atom() | string(),[any()]) -> {'tree',atom(),{'attr',0,[],'none'},_}. |
49 | | --spec belongs_to_forms(atom() | string() | number(),atom(),atom()) -> {'tree',atom(),{'attr',_,[any()],{_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],{_,_,_}},_}. |
50 | | - |
51 | | --spec counter_getter_forms([atom()]) -> syntaxTree(). |
52 | | --spec counter_reset_forms([name()]) -> syntaxTree(). |
53 | | --spec counter_incr_forms([name()]) -> syntaxTree(). |
54 | | --spec counter_name_forms(name()) -> syntaxTree(). |
55 | | --spec parameter_to_colname(atom()) -> string(). |
| 37 | + |
| 38 | +-spec get_attributes_forms(atom(),[any()]) -> syntaxTree(). |
| 39 | +-spec set_attributes_forms(atom(),[any()]) -> syntaxTree(). |
| 40 | +-type assoc() :: {has, {atom(), integer()}} | |
| 41 | + {has, {atom(), integer(), [any()]}} | |
| 42 | + {belongs_to, atom()}. |
| 43 | +-spec association_forms(atom(),[assoc()]) -> [any(),...]. |
| 44 | + |
| 45 | +-spec belongs_to_list_forms([{atom(),any()}]) -> syntaxTree(). |
| 46 | + |
| 47 | +-spec belongs_to_list_make_list([{atom(),atom()}]) -> syntaxTree(). |
| 48 | +-spec attribute_names_forms(name(),[atom()]) -> syntaxTree(). |
| 49 | +-spec has_one_forms(name(),atom(),[any()]) -> syntaxTree(). |
| 50 | +-spec has_many_forms(atom(),atom(), pos_integer()|all|many, [any()]) -> syntaxTree(). |
| 51 | +-spec first_or_undefined_forms( syntaxTree()) -> syntaxTree(). |
| 52 | +-spec has_many_application_forms(name(),{'tree',atom(),{'attr',_,[any()],'none' | {_,_,_}},_} | {'wrapper',atom(),{'attr',_,[any()],'none' | {_,_,_}},_}, |
| 53 | + pos_integer(), |
| 54 | + name(), |
| 55 | + name(), |
| 56 | + [atom()]) |
| 57 | + -> syntaxTree(). |
| 58 | + |
| 59 | +-spec has_many_query_forms_with_conditions(name()) -> syntaxTree(). |
| 60 | +-spec belongs_to_forms(atom() | string() | number(), |
| 61 | + atom(), |
| 62 | + atom()) -> syntaxTree(). |
| 63 | +-spec has_many_query_forms(name()) -> syntaxTree(). |
| 64 | +-spec counter_getter_forms([atom()]) -> syntaxTree(). |
| 65 | +-spec counter_reset_forms([name()]) -> syntaxTree(). |
| 66 | +-spec counter_incr_forms([name()]) -> syntaxTree(). |
| 67 | +-spec counter_name_forms(name()) -> syntaxTree(). |
| 68 | +-spec parameter_to_colname(atom()) -> string(). |
56 | 69 | %% @spec compile( File::string() ) -> {ok, Module} | {error, Reason} |
57 | 70 | %% @equiv compile(File, []) |
58 | 71 | compile(File) -> |
@@ -425,27 +438,30 @@ belongs_to_list_forms(BelongsToList) -> |
425 | 438 | erl_syntax:atom(Type)]) |
426 | 439 | end, BelongsToList))])])), |
427 | 440 |
|
428 | | - erl_syntax:add_precomments([erl_syntax:comment( |
429 | | - ["% @spec belongs_to() -> [{atom(), BossRecord}]", |
430 | | - lists:concat(["% @doc Retrieve all of the `belongs_to' associations at once."])])], |
431 | | - erl_syntax:function( |
432 | | - erl_syntax:atom(belongs_to), |
433 | | - [erl_syntax:clause([], none, [erl_syntax:list(lists:map( |
434 | | - fun({Name, _Type}) -> erl_syntax:tuple([ |
435 | | - erl_syntax:atom(Name), |
436 | | - erl_syntax:application(none, erl_syntax:atom(Name), [])]) |
437 | | - end, BelongsToList))])])) |
| 441 | + erl_syntax:add_precomments([erl_syntax:comment( |
| 442 | + ["% @spec belongs_to() -> [{atom(), BossRecord}]", |
| 443 | + lists:concat(["% @doc Retrieve all of the `belongs_to' associations at once."])])], |
| 444 | + erl_syntax:function( |
| 445 | + erl_syntax:atom(belongs_to), |
| 446 | + [erl_syntax:clause([], none, [erl_syntax:list(belongs_to_list_make_list(BelongsToList))])])) |
438 | 447 | ]. |
439 | 448 |
|
| 449 | +belongs_to_list_make_list(BelongsToList) -> |
| 450 | + lists:map( |
| 451 | + fun({Name, _Type}) -> erl_syntax:tuple([ |
| 452 | + erl_syntax:atom(Name), |
| 453 | + erl_syntax:application(none, erl_syntax:atom(Name), [])]) |
| 454 | + end, BelongsToList). |
| 455 | + |
440 | 456 | attribute_names_forms(ModuleName, Parameters) -> |
441 | 457 | [ erl_syntax:add_precomments([erl_syntax:comment( |
442 | | - ["% @spec attribute_names() -> [atom()]", |
443 | | - lists:concat(["% @doc A list of the lower-case `", ModuleName, "' parameters."])])], |
444 | | - erl_syntax:function( |
445 | | - erl_syntax:atom(attribute_names), |
446 | | - [erl_syntax:clause([], none, [erl_syntax:list(lists:map( |
447 | | - fun(P) -> erl_syntax:atom(parameter_to_colname(P)) end, |
448 | | - Parameters))])]))]. |
| 458 | + ["% @spec attribute_names() -> [atom()]", |
| 459 | + lists:concat(["% @doc A list of the lower-case `", ModuleName, "' parameters."])])], |
| 460 | + erl_syntax:function( |
| 461 | + erl_syntax:atom(attribute_names), |
| 462 | + [erl_syntax:clause([], none, [erl_syntax:list(lists:map( |
| 463 | + fun(P) -> erl_syntax:atom(parameter_to_colname(P)) end, |
| 464 | + Parameters))])]))]. |
449 | 465 |
|
450 | 466 | has_one_forms(HasOne, ModuleName, Opts) -> |
451 | 467 | Type = proplists:get_value(module, Opts, HasOne), |
@@ -542,9 +558,13 @@ has_many_forms(HasMany, ModuleName, Limit, Opts) -> |
542 | 558 |
|
543 | 559 | first_or_undefined_forms(Forms) -> |
544 | 560 | erl_syntax:case_expr(Forms, |
545 | | - [erl_syntax:clause([erl_syntax:list([erl_syntax:variable(?PREFIX++"Record")])], none, |
546 | | - [erl_syntax:variable(?PREFIX++"Record")]), |
547 | | - erl_syntax:clause([erl_syntax:underscore()], none, [erl_syntax:atom(undefined)])]). |
| 561 | + [erl_syntax:clause([erl_syntax:list([erl_syntax:variable(?PREFIX++"Record")])], |
| 562 | + none, |
| 563 | + [erl_syntax:variable(?PREFIX++"Record")]), |
| 564 | + |
| 565 | + erl_syntax:clause([erl_syntax:underscore()], |
| 566 | + none, |
| 567 | + [erl_syntax:atom(undefined)])]). |
548 | 568 |
|
549 | 569 | has_many_query_forms(ForeignKey) -> |
550 | 570 | erl_syntax:list([ |
|
0 commit comments