Shapt v0.0.2 Shapt.Adapter behaviour View Source
A behaviour that defines the basic callbacks that a Shapt Adapter needs to implement. This callbacks are just the very basic behavior that an adapter might have.
Link to this section Summary
Types
State of the GenServer created in a module that uses Shapt
.
environment
- this is a way for adapters to know in which environment they are running, in case releases are being used.
ets
- reference of the ets table created when ets_cache
option is set to true.
ets_loaded
- says if ets
has been loaded with load_all/1
execution.
toggles
- take a loot at toggles()
adapter
- Module that is configured as the adapter.
adapter_opts
- configuration for the adapter
The name of toggle set in the Shapt config.
Toggle options configured at keyword list in the Shapt config.
Common options are key_name
and deadline
. deadline
is required for the mix task Mix.Tasks.Shapt.Expired
.
Custom Adapters can define more options.
Keyword list containing all toggle and toggle options config.
Callbacks
Verifies if a given toggle is enabled true or false.
This only gonna be used if ets_cache
option is set to false.
It receives the toggle_name()
of the key being verified and the state()
of the Genserver.
It include all the state()
because adapter configuration can be used by the adapter.
Reiceves toggle_name()
and toggle_opts
and should return the representation of the toggle name the way the adapter understands it.
This is used mainly because when ets_cache
and ets_loaded
are both set to true, the GenServer will bypass the need to use the adapter.
Use the same value returned here to load the toggle in the load_all/1
function.
Load all toggles current value to the ets table. Please make sure to enforce values are only boolean
Produces the template outputed by Mix.Tasks.Shapt.Template
.
It receives the toggles keywordlist and the adapter options and returns the binary representing the template.
Link to this section Types
State of the GenServer created in a module that uses Shapt
.
environment
- this is a way for adapters to know in which environment they are running, in case releases are being used.
ets
- reference of the ets table created when ets_cache
option is set to true.
ets_loaded
- says if ets
has been loaded with load_all/1
execution.
toggles
- take a loot at toggles()
adapter
- Module that is configured as the adapter.
adapter_opts
- configuration for the adapter
The name of toggle set in the Shapt config.
Toggle options configured at keyword list in the Shapt config.
Common options are key_name
and deadline
. deadline
is required for the mix task Mix.Tasks.Shapt.Expired
.
Custom Adapters can define more options.
Keyword list containing all toggle and toggle options config.
Link to this section Callbacks
enabled?(toggle_name, state)
View Sourceenabled?(toggle_name(), state()) :: boolean()
Verifies if a given toggle is enabled true or false.
This only gonna be used if ets_cache
option is set to false.
It receives the toggle_name()
of the key being verified and the state()
of the Genserver.
It include all the state()
because adapter configuration can be used by the adapter.
key_name(toggle_name, toggle_opts)
View Sourcekey_name(toggle_name(), toggle_opts()) :: any()
Reiceves toggle_name()
and toggle_opts
and should return the representation of the toggle name the way the adapter understands it.
This is used mainly because when ets_cache
and ets_loaded
are both set to true, the GenServer will bypass the need to use the adapter.
Use the same value returned here to load the toggle in the load_all/1
function.
Load all toggles current value to the ets table. Please make sure to enforce values are only boolean
Produces the template outputed by Mix.Tasks.Shapt.Template
.
It receives the toggles keywordlist and the adapter options and returns the binary representing the template.