Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phoenixframework/ex_conf
Simple Elixir Configuration Management
https://github.com/phoenixframework/ex_conf
Last synced: about 1 month ago
JSON representation
Simple Elixir Configuration Management
- Host: GitHub
- URL: https://github.com/phoenixframework/ex_conf
- Owner: phoenixframework
- License: mit
- Archived: true
- Created: 2014-02-12T22:11:15.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-05T18:42:31.000Z (over 10 years ago)
- Last Synced: 2024-10-02T06:43:52.849Z (2 months ago)
- Language: Elixir
- Homepage:
- Size: 363 KB
- Stars: 36
- Watchers: 8
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Simple Elixir Configuration Management. (Configuration)
- fucking-awesome-elixir - ex_conf - Simple Elixir Configuration Management. (Configuration)
- awesome-elixir - ex_conf - Simple Elixir Configuration Management. (Configuration)
README
# ExConf
> Simple Elixir Configuration Management## Deprecated
ExConf has been replaced by [Mix Configuration](http://elixir-lang.org/docs/stable/mix/Mix.Config.html). See the Phoenix README for new [configuration instructions](https://github.com/phoenixframework/phoenix#configuration).## Features
- Configuration definitions are *evaluated at runtime*, but merged/defaulted at compile time, allowing runtime dependent lookups. (i.e. `System.get_env`)
- Configuration modules can extend other configurations for overrides and defaults
- Evironment based lookup for settings based on provided `env_var`## Simple Example
```elixirdefmodule MyApp.Config do
use ExConf.Configconfig :router, ssl: true,
domain: "example.dev",
port: System.get_env("PORT")config :session, secret: "secret"
endiex> MyApp.Config.router[:domain]
"example.dev"defmodule MyApp.OtherConfig do
use MyApp.Configconfig :session, secret: "123password"
endiex> MyApp.OtherConfig.session[:secret]
"123password"
iex> MyApp.OtherConfig.router[:ssl]
true
```## Environment Based Configuration
First, establish a *base* configuration module that uses `ExConf.Config` and
provide an `env_var` option for `System.get_env` lookup at runtime of the current
application environment.
```elixir
defmodule MyApp.Config do
use ExConf.Config, env_var: "MIX_ENV"config :router, ssl: true
config :twitter, api_token: System.get_env("API_TOKEN")
end
```Next, define "submodules" for each environment you need overrides or additional settings for.
The *base* config module will look for a "submodule" whos name is the value of
`:env_var` fetched from `System.get_env` in capitalized form.
This allows environment specific lookup at runtime via the `env/0` function on the base module.
If the environment specific config module does not exist, it falls back to the base module.Here's what a Dev enviroment config module would look like for `System.get_env("MIX_ENV") == "dev"`:
```elixir
defmodule MyApp.Config.Dev do
use MyApp.Configconfig :router, ssl: false
config :twitter, api_token: "ABC"
endiex> System.get_env("MIX_ENV")
"dev"iex> MyApp.Config.env
MyApp.Config.Deviex> MyApp.Config.env.router[:ssl]
false
```