1
1
Fork
You've already forked smart_config
0
A DSL for reading and accessing static configuration
  • Ruby 100%
dmathieu 36bd227614
All checks were successful
Linting / lint (push) Successful in 57s
Tests / test (3.3) (push) Successful in 37s
Tests / test (3.4) (push) Successful in 36s
Tests / test (4) (push) Successful in 1m16s
Update dependency rubocop to v1.88.2 ( #129 )
This PR contains the following updates:
| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [rubocop](https://rubocop.org/) ([source](https://github.com/rubocop/rubocop), [changelog](https://github.com/rubocop/rubocop/releases/tag/v1.88.2)) | `1.88.1` → `1.88.2` | ![age](https://developer.mend.io/api/mc/badges/age/rubygems/rubocop/1.88.2?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/rubygems/rubocop/1.88.1/1.88.2?slim=true) |
>  **Important**
>
> Release Notes retrieval for this PR were skipped because no github.com credentials were available.
> If you are self-hosted, please see [this instruction](https://github.com/renovatebot/renovate/blob/master/docs/usage/examples/self-hosting.md#githubcom-token-for-release-notes).
---
### Configuration
📅 **Schedule**: (UTC)
- Branch creation
 - At any time (no schedule defined)
- Automerge
 - At any time (no schedule defined)
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box
---
This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNTkuMiIsInVwZGF0ZWRJblZlciI6IjQzLjI1OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJydWJ5Il19-->
Co-authored-by: Renovate Bot <forgejo-renovate-action@dmathieu.com>
Reviewed-on: #129 
2026年07月14日 10:41:57 +02:00
.forgejo/workflows Update https://data.forgejo.org/actions/cache action to v6 ( #128 ) 2026年07月07日 09:06:24 +02:00
lib release v0.1.0 2026年04月15日 13:14:09 +02:00
spec Refresh ENV on every walk instead of snapshotting at initialization 2026年04月15日 13:13:12 +02:00
.gitignore add code coverage 2024年02月28日 18:28:53 +01:00
.rubocop.yml Refresh ENV on every walk instead of snapshotting at initialization 2026年04月15日 13:13:12 +02:00
.ruby-version Update dependency ruby to v4.0.5 ( #122 ) 2026年05月26日 13:41:14 +02:00
Gemfile add code coverage 2024年02月28日 18:28:53 +01:00
Gemfile.lock Update dependency rubocop to v1.88.2 ( #129 ) 2026年07月14日 10:41:57 +02:00
LICENSE switch license to AGPL 2025年09月16日 11:05:05 +02:00
Rakefile init repository 2024年02月27日 09:41:03 +01:00
README.md fix gem name in readme 2025年01月23日 11:08:10 +01:00
renovate.json fix json 2025年08月26日 18:16:55 +02:00
smart_config.gemspec move repo in gemspec 2025年08月26日 14:31:24 +02:00

Smart Config

We have "smart" toothbrushes these days, so why not smart configuration?

Note: As you can see in the version number, this gem is still in a very early version, and you should expect that there may be breaking changes until we reach 1.0.

Usage

Smart Config allows you to define a static configuration and access it from anywhere within your application. It will try to read the configuration from a YAML file, and fallback on environment variables.

Installation

Add the smart_config dependency to you Gemfile:

gem 'smart_config'

Usage

Then, create a new config class that, and define the configuration you need:

class Config
	extend SmartConfig::Config
	# Optional. Will default to `config/config.yml`
	config_path 'config/app_config.yml'
	value :app_name, default: 'My App'
	group :smtp do
		value :hostname
		value :port, format: :integer
		value :username
		value :password
	end
	group :redis do
		group :connection do
			value :hostname
			value :port
			value :username
			value :password
		end
		value :timeout
	end
end

Then, within your application, you can call:

Config.redis.connection.hostname

To access the configuration value, from the following YAML file for example:

redis:connection:hostname:'localhost'

For values that are not in the YAML config, the tool will try reading it from environment variables, such as (from the previous configuration):

REDIS_CONNECTION_PASSWORD

Value Options

Values can use options, which can be set after the value name. For example:

value :hostname, default: 'localhost'

All available options are:

name description
default Sets a default value for the field, if no configuration could be found. If this option is not set, getting an unset field will raise an exception.
format Sets the format of the field. If this option is not set, the field will be formatted as string.