The project is in a healthy, maintained state
A zero-dependency Ruby gem for layered configuration resolution. Define typed config keys with defaults, load from YAML files, and override with environment variables.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

philiprehberger-config_kit

Gem Version CI License

Layered configuration with YAML, ENV, and defaults.

Requirements

  • Ruby >= 3.1

Installation

Add to your Gemfile:

gem "philiprehberger-config_kit"

Or install directly:

gem install philiprehberger-config_kit

Usage

Basic (defaults only)

require "philiprehberger/config_kit"

config = Philiprehberger::ConfigKit.define do
  string :app_name, default: "my-app"
  integer :port, default: 3000
  boolean :debug, default: false
end

config[:app_name] # => "my-app"
config[:port]     # => 3000
config[:debug]    # => false

With YAML file

# config.yml
app_name: "production-app"
port: 8080
config = Philiprehberger::ConfigKit.define(yaml: "config.yml") do
  string :app_name, default: "my-app"
  integer :port, default: 3000
  boolean :debug, default: false
end

config[:app_name] # => "production-app" (from YAML)
config[:port]     # => 8080             (from YAML)
config[:debug]    # => false            (from default)

With ENV overrides

config = Philiprehberger::ConfigKit.define(yaml: "config.yml") do
  string  :app_name, default: "my-app", env: "APP_NAME"
  integer :port,     default: 3000,     env: "PORT"
  boolean :debug,    default: false,    env: "DEBUG"
end

# ENV["PORT"] = "9090" would override both YAML and default
config[:port] # => 9090

Resolution order

Values are resolved in this order (highest priority first):

  1. ENV variables (if env: key is set and the variable exists)
  2. YAML file (if yaml: path is provided and the key exists)
  3. Defaults (from the schema definition)

Export all values

config.to_h
# => { app_name: "my-app", port: 3000, debug: false }

API

Method Description
Philiprehberger::ConfigKit.define(yaml:, env:, &block) Create a new config store
config.get(key) / config[key] Get a config value
config.to_h Export all values as a hash
config.keys List all defined keys
config.key?(key) Check if a key is defined

Schema DSL

Method Type Cast behavior
string(name, default:, env:) :string .to_s
integer(name, default:, env:) :integer Integer(value)
float(name, default:, env:) :float Float(value)
boolean(name, default:, env:) :boolean true/"true"/"1"/"yes" are truthy

Development

bundle install
bundle exec rspec
bundle exec rubocop

License

MIT