lc0815
July 22, 2021, 5:09pm
1
what does this code actually do, it seems repetitive:
@entity_fields %{
"vendor" => [
%{"field" => "name", "label" => "Name"},
%{"field" => "type", "label" => "Type"},
%{"field" => "phone", "label" => "Phone Number"},
%{"field" => "fax", "label" => "Fax Number"},
%{"field" => "website", "label" => "Website"},
%{"field" => "billingAddress", "label" => "Street"},
%{"field" => "billingCity", "label" => "City"},
%{"field" => "billingStateCode", "label" => "State"},
%{"field" => "billingPostalCode", "label" => "Zip"}
],
"contact" => [
%{"field" => "name", "label" => "Name"},
%{"field" => "phone", "label" => "Phone"},
%{"field" => "fax", "label" => "Fax"},
%{"field" => "mailingStreet", "label" => "Street"},
%{"field" => "mailingCity", "label" => "City"},
%{"field" => "mailingStateCode", "label" => "State"},
%{"field" => "mailingPostalCode", "label" => "Zip"}
],
"product" => [
%{"field" => "modelName", "label" => "Name"},
%{"field" => "modelId", "label" => "Id"},
%{"field" => "salesNotes", "label" => "Notes"}
]
}
It’s a literal. Kind of hard for us to guess what it does other than set itself.
It sets the value of a module attribute that you can then reuse in the same module’s functions.
Did you go through the Elixir introduction tutorial?
1 Like
lc0815
July 22, 2021, 5:23pm
4
yes, but sometimes when you see code like this, it’s more useful to ask a question from people who are actually using this stuff… as you know sometimes the docs don’t tell the whole story… pardon the interruption
lc0815
July 22, 2021, 5:26pm
5
this is on a file by itself
defmodule GenericEntityDetails do
constants
end
but since I asked the question, it forced me to understand it a lot better,
thanks.
1 Like
So… It does nothing? Strange
1 Like
(By default @ attributes are not persisted beyond compile time… You can do something special to persist them, they are still rather tricky to get at at runtime and you’re kind of “not supposed to” in most cases)
1 Like
Sebb
July 22, 2021, 8:59pm
8
Are you saying that you could somehow access
defmodule Foo do
@bar :baz
end
@bar
here?
defmodule M do
Module.register_atttribute(__MODULE__, :foo, persist: true)
@foo "bar"
end
M.__info__(:attributes)
With great power comes great responsibility, etc.
1 Like
Linc01
July 23, 2021, 8:06am
10
This code is a “menu” and waiting for a “customer” to parse it.