ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - KamilLelonek/figaro-elixir: Environmental variables manager based on Figaro for Elixir projects
Environmental variables manager based on Figaro for Elixir projects - KamilLelonek/figaro-elixir
Visit Site

GitHub - KamilLelonek/figaro-elixir: Environmental variables manager based on Figaro for Elixir projects

GitHub - KamilLelonek/figaro-elixir: Environmental variables manager based on Figaro for Elixir projects

Figaro Elixir

Build Status

This project is based on figaro gem for Rails written by Steve Richert.

It's was created to manage ENV configuration for Elixir applications.

How does it work?

Figaro parses a git-ignored YAML file in your application and loads its values into environmental variables.

This is very handy for production environments when you don't want to store some of credentials in your repository.

Installation

Add Figaro Elixir as a dependency in your mix.exs file.

defp deps do
  [
    # ...
    {:figaro_elixir, "~> 1.0.0"}
  ]
end

You should also update your applications list to include Figaro:

def application do
  [
     applications: [
       # ...
       :figaro_elixir
     ]
  ]
end

Once you've done that, run mix deps.get in your command line to fetch the dependency.

Usage

The basic requirement is to have application.yml file in your project config directory.

Figaro will read it, parse it and use it to store environmental variables.

Please note that ENV is a simple key/value store with the following features:

  • all values are converted to strings
  • deeply nested configuration structures are not possible

Simple example

You can very easily start using Figaro for Elixir. Just create an appropriate file:

# config/application.yml

foo: bar
baz: qux

And run iex -S mix in your terminal. You will have an access to configuration values via FigaroElixir.env or System environmental variables:

iex(1)> FigaroElixir.env
%{"baz" => "qux", "foo" => "bar"}
iex(2)> FigaroElixir.env["baz"]
"qux"
iex(3)> System.get_env("foo")
nil
iex(4)> System.get_env("FOO")
"bar"

Keep in mind that system environmental variables keys are uppercased.

Environment-specific configuration

The power of Figaro elixir comes from distinguishing environments based on Mix.env property.

You may have a file defined like this:

a: a
b: ~

test:
  c: 1
  d: ~

And then after running MIX_ENV=test iex -S mix you will see:

iex(1)> FigaroElixir.env
%{"a" => "a", "b" => "~", "c" => "1", "d" => "~"}
iex(2)> FigaroElixir.env["c"]
"1"
iex(3)> System.get_env("C")
"1"

That's it. You don't have to do anything more.

Caveats

If you are using escript build tool, you need to have :mix among your apps in mix.exs file and copy application.yml file to your rel/project_name/config directory.

About the author

My name is Kamil Lelonek, I'm a full-stack developer and polyglot programmer. I love playing with different languages, technologies and tools. You can visit my website read my blog or follow me on twitter. In case of any problems or suggestions do not hesitate and create a pull request.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory