Since attributes are inlined once the module is compiled, I assume their values are constant. If possible, I'd like to define an attribute in terms of previously created attributes. I also want to be able to access them from the outside, my current approach is this
@required_fields ~w(email)
@optional_fields ~w(password role name last_name age country)
def required_fields, do: @required_fields
def optional_fields, do: @optional_fields
@all_fields required_fields ++ optional_fields
def all_fields, do: @all_fields
but I get this error
== Compilation error on file web/models/user.ex == ** (CompileError) web/models/user.ex:22: undefined function required_fields/0 (elixir) expanding macro: Kernel.@/1 web/models/user.ex:22: AristaServer.User (module) (elixir) lib/kernel/parallel_compiler.ex:97: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8
Any way to achieve something similar? I don't want to recalculate the all_fields
list everytime, seems wasteful. Also, I don't want to have to copy and past both list into a third list, looks error prone.