Once Shapt
is one of his dependencies. You gonna need to create a feature toggle module:
defmodule TestModule do
use Shapt,
adapter: {Shapt.Adapters.Env, []},
toggles: [
feature_x?: %{
key: "MYAPP_FEATURE_X",
deadline: ~D[2019-12-31]
},
feature_y?: %{
deadline: ~D[2009-12-31]
}
]
end
This module is a worker that you need to add to your supervision tree. Shapt
will create the proper child_spec/1
and start_link/1
functions.
All the state of the toggles are kept inside an ets table.
adapter
: receives a keyword list of adapters by environment.toggles
: receives a keyword list of toggles to be configured.
Just by using
Shapt you gonna have some extra functions on your feature toggle
module:
Besides the key named functions you gonna have toggle/2
. It can be used to
evaluate the feature toggle and what to do when it's on or off. Some usage
examples:
# just returning values
TestModule.toggle(:feature_x?, on: FeatureX, off: OldFeature)
# applying functions and params:
TestModule.toggle(:feature_x?, on: {&Feature.x/2, params_x}, off: {&Feature.old/2, params_old})
# applying module, function_name and params
TestModule.toggle(:feature_x?, on: {ModuleX, :function, [paramsx]}, off: {Module, :fuction, [params]})
In those two last examples we use the apply
function, be aware of that when
using this feature. So make sure that the params
provided are always a list which
the size is the same as the provided function arity.
It receives the name of a toggle and says if it's expired or not.
It receives the name of a toggle and says if it's enabled or not.
List all expired toggles
Return the binary representing the template file generated by the Adapter.
Reloads the ets table with the current state of toggles according to the adapter options.
Shapt.Adapters.Env
will work directly with environment variables using the System.get_env/1
or loading it from a configuration file.