Skip to content

Instantly share code, notes, and snippets.

@jmglov
Created May 18, 2016 12:06
Show Gist options
  • Save jmglov/750aff7bc70f2f04ea8df91be0f1e587 to your computer and use it in GitHub Desktop.
Save jmglov/750aff7bc70f2f04ea8df91be0f1e587 to your computer and use it in GitHub Desktop.
Example usage for config.ex
defmodule Foo do
use Config
cfg :disable_foo?, :boolean
cfg :bar_delay, :integer
cfg :baz_name
cfg :blahs, {:list, :float}
cfg :blerks, {:set, :atom}
def print_stuff do
IO.puts "Disable foo? #{disable_foo?}"
IO.puts "Bar delay: #{bar_delay}"
IO.puts "Baz name: #{baz_name}"
IO.puts "Blahs: #{inspect blahs}"
IO.puts "Blerks: #{inspect blerks}"
end
end
#####
# Example config.exs
use Mix.Config
config :my_app, Foo,
disable_foo?: false,
bar_delay: 42,
baz_name: "Baz, James Baz",
blahs: [1.23, 4.56, 7.89],
blerks: MapSet.new([:green_eggs, :ham])
#####
# Example environment variables
# FOO_DISABLE_FOO=true
# FOO_BAR_DELAY=747
# FOO_BAZ_NAME='James T. Kirk'
# FOO_BLAHS=9.87,6.54,3.21
# FOO_BLERKS=spam,jam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment