StrawHat v0.6.0 StrawHat.Configurable View Source

It defines a configurable module. A configurable module expose config function that returns the configuration of the module based a merge strategy.

The configuration will use three configurations:

  • Using the macro parameters, most likely used for static values.
  • Using Config module, most likely used for environment-based values.
  • Runtime based on the parameters, most likely used when you want to control the values at runtime.

Static Configuration

When you need to define default values that do not require runtime execution nor they are based on the environment. They are most likely static values.

defmodule MyConfigurableModule do
  use StrawHat.Configurable,
    config: [
      site: "https://myproductionsite.com"
    ]
end

Environment Configuration

When you pass the otp_app, we will lookup based on the OTP app name and the module name.

defmodule MyConfigurableModule do
  use StrawHat.Configurable, otp_app: :my_app
end

Then you can configure the values in your config files.

config :my_app, MyConfigurableModule,
  some_value_here: ""

This will allow you to swap values based on the environment.

Runtime Configuration

Since your module will contain the config function, you can always call it with extra configs.

MyConfigurableModule.config([
  another_value: ""
])