Skip to content
Pedro Belo edited this page Jul 14, 2015 · 2 revisions

Pliny takes all of its configuration parameters via environment variables.

Take a look at config/config.rb whenever you need to read or set new parameters. It relies on Pliny helpers to validate, cast and set default values for env vars.

Usage

Lets say you're adding a Redis cache to your app.

The first step is to set a new, required Config:

module Config
  extend Pliny::CastingConfigHelpers

  mandatory :redis_url, string
end

Now use this interface instead of going to ENV directly:

redis = Redis.new(url: Config.redis_url)

If REDIS_URL is not present in the environment you're going to see this error when trying to access it:

lib/pliny/config_helpers.rb:4:in `fetch': key not found: "REDIS_URL" (KeyError)

Fix it by setting the env var in .env (the address of your local Redis) and in .env.sample (the default value for new developers):

REDIS_URL=redis://localhost:6379

Further reading