config_tuples v0.2.5 ConfigTuples.Provider View Source

This module provides an implementation of Distilery’s configuration provider behavior that changes runtime config tuples for the value.

Usage

Add the following to your rel/config.exs

release :myapp do

# ...snip...
set config_providers: [
  ConfigTuples.Provider
]

end

This will result in ConfigTuples.Provider being invoked during boot, at which point it will evaluate the current configuration for all the apps and replace the config tuples when needed, persisting it in the configuration.

Config tuples

The config tuple always start with :system, and can have some options as keyword, the syntax are like this:

  • {:system, env_name}
  • {:system, env_name, opts}

The available options are:

  • type: Type to cast the value, one of :string, :integer, :atom, :boolean. Default to :string
  • default: Default value if the environment variable is not setted. Default no nil
  • transform: Function to transform the final value, the syntax is {Module, :function}
  • required: Set to true if this environment variable needs to be setted, if not setted it will raise an error. Default no false

For example:

  • {:system, "MYSQL_PORT", type: :integer, default: 3306}
  • {:system, "ENABLE_LOG", type: :boolean, default: false}
  • {:system, "HOST", transform: {MyApp.UrlParser, :parse}}

If you need to store the literal values {:system, term()}, {:system, term(), Keyword.t()}, you can use {:system, :literal, term()} to disable ConfigTuples config interpolation. For example:

  • {:system, :literal, {:system, "HOST}}

Link to this section Summary

Link to this section Functions