specify v0.10.0 Specify.Provider.MixEnv View Source

A Configuration Provider source based on Mix.env() / Application.get_env/2.

Examples

The following examples use the following specification for reference:

defmodule Elixir.Pet do
  require Specify
  Specify.defconfig do
    @doc "The name of the pet"
    field :name, :string
    @doc "is it a dog or a cat?"
    field :kind, :atom
  end
end

Link to this section Summary

Functions

By default, will try to use Application.get_all_env(YourConfigModule) to fetch the source's configuration. A different application name can be used by supplying a different application argument.

Link to this section Functions

Link to this function

new(application \\ nil, key \\ nil, options \\ [])

View Source

By default, will try to use Application.get_all_env(YourConfigModule) to fetch the source's configuration. A different application name can be used by supplying a different application argument.

If the actual configuration is only inside one of the keys in this application, the second field key can also be provided.

iex> Application.put_env(Elixir.Pet, :name, "Timmy")
iex> Application.put_env(Elixir.Pet, :kind, "cat")
iex> Pet.load(sources: [Specify.Provider.MixEnv.new()])
%Pet{name: "Timmy", kind: :cat}
iex> Pet.load(sources: [Specify.Provider.MixEnv.new(Elixir.Pet)])
%Pet{name: "Timmy", kind: :cat}

iex> Application.put_env(:second_pet, :name, "John")
iex> Application.put_env(:second_pet, :kind, :dog)
iex> Pet.load(sources: [Specify.Provider.MixEnv.new(:second_pet)])
%Pet{name: "John", kind: :dog}