What does this code mean?

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?

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

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.

So… It does nothing? Strange :smiley:

(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)

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.

This code is a “menu” and waiting for a “customer” to parse it.