RefData behaviour (RefData v0.2.1) View Source
RefData is a library for Phoenix projects that lets you provide reference data for your forms (e.g. Gender) without using a database table. It has been written as tool for POC development but can be used in PROD for fields that are common and do not form part of complex queries.
Link to this section Summary
Callbacks
Returns a list of data for the provided key. If the json defines grouped data it will return grouped data.
You can pass params to the get function. Keywords available
Returns a list of all key values from the underlying data store. It will match the keys used in the individual json files
Link to this section Callbacks
Specs
get(key :: String) :: List
Returns a list of data for the provided key. If the json defines grouped data it will return grouped data.
Examples
iex(1)> MyRefData.get("gender")
[
[key: "Male", value: "Male"],
[key: "Female", value: "Female"],
[key: "Non-binary", value: "non-binary"]
]
iex(1)> MyRefData.get("countries")
[
Asia: [
[key: "Australia", value: "Australia"],
[key: "New Zealand", value: "New Zealand"]
],
Americas: [
[key: "Canada", value: "Canada"],
[key: "USA", value: "USA"]]
]
Specs
get(key :: String, {:disabled, []}) :: List
You can pass params to the get function. Keywords available
- disabled: [] - Will return the data with the listed fields disabled
Example
iex(1)> MyRefData.get("gender", disabled: ["Female"]) [
[key: "Male", value: "Male"],
[key: "Female", value: "Female", disabled: true],
[key: "Non-binary", value: "Non-binary"]
]
Specs
list_all_keys() :: List
Returns a list of all key values from the underlying data store. It will match the keys used in the individual json files
Examples
iex> RefData.list_all_keys()
["key1", "key2"]