Skip to content

Elixir library to provide constants functionality.

License

Notifications You must be signed in to change notification settings

rtvu/define_constants

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DefineConstants

Elixir library to provide constants functionality.

Usage

DefineConstants provides the define macro to create custom constants. Constants should live inside their own modules.

defmodule MyConstants do
  use DefineConstants

  define(:name, "MyApplication")
  define(:number, 7)
end

The define macro takes atom keys and arbitrary values. The provided key/value pairs are used to create the constant macro.

Caller functions use the constant macro to retrieve the constant values.

defmodule Caller do
  import MyConstants

  constant(:name)
  constant(:number) + 10
end

Since constant is a macro, at compile time, all constant calls are converted to their appropriate values.

Installation

To use DefineConstants in your Mix projects, first add DefineConstants as a dependency:

def deps do
  [
    {:define_constants, "~> 0.1.0"}
  ]
end

After adding DefineConstants as a dependency, run mix deps.get to install it.

About

Elixir library to provide constants functionality.

Resources

License

Stars

Watchers

Forks

Languages