README.md in runger_config-3.0.1 vs README.md in runger_config-4.0.0
- old
+ new
@@ -1,22 +1,22 @@
-[![Cult Of Martians](http://cultofmartians.com/assets/badges/badge.svg)](https://cultofmartians.com/tasks/anyway-config-options-parse.html#task)
+[![Cult Of Martians](http://cultofmartians.com/assets/badges/badge.svg)](https://cultofmartians.com/tasks/runger-config-options-parse.html#task)
[![Gem Version](https://badge.fury.io/rb/runger_config.svg)](https://rubygems.org/gems/runger_config) [![Build](https://github.com/davidrunger/runger_config/workflows/Build/badge.svg)](https://github.com/davidrunger/runger_config/actions)
[![JRuby Build](https://github.com/davidrunger/runger_config/workflows/JRuby%20Build/badge.svg)](https://github.com/davidrunger/runger_config/actions)
[![TruffleRuby Build](https://github.com/davidrunger/runger_config/workflows/TruffleRuby%20Build/badge.svg)](https://github.com/davidrunger/runger_config/actions)
-# Anyway Config
+# Runger Config
> One configuration to rule all data sources
-Anyway Config is a configuration library for Ruby gems and applications.
+Runger Config is a configuration library for Ruby gems and applications.
-As a library author, you can benefit from using Anyway Config by providing a better UX for your end-users:
+As a library author, you can benefit from using Runger Config by providing a better UX for your end-users:
- **Zero-code configuration** — no more boilerplate initializers.
- **Per-environment and local** settings support out-of-the-box.
-For application developers, Anyway Config could be useful to:
+For application developers, Runger Config could be useful to:
- **Keep configuration organized** and use _named configs_ instead of bloated `.env`/`settings.yml`/whatever.
- **Free code of ENV/credentials/secrets dependency** and use configuration classes instead—your code should not rely on configuration data sources.
**NOTE:** this readme shows documentation for 2.x version.
@@ -25,11 +25,11 @@
<a href="https://evilmartians.com/?utm_source=runger_config">
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
## Links
-- [Anyway Config: Keep your Ruby configuration sane](https://evilmartians.com/chronicles/anyway-config-keep-your-ruby-configuration-sane?utm_source=runger_config)
+- [Runger Config: Keep your Ruby configuration sane](https://evilmartians.com/chronicles/runger-config-keep-your-ruby-configuration-sane?utm_source=runger_config)
## Table of contents
- [Main concepts](#main-concepts)
- [Installation](#installation)
@@ -55,15 +55,15 @@
- [OptionParser integration](#optionparser-integration)
- [RBS support](#rbs-support)
## Main concepts
-Anyway Config abstractize the configuration layer by introducing **configuration classes** which describe available parameters and their defaults. For [example](https://github.com/palkan/influxer/blob/master/lib/influxer/config.rb):
+Runger Config abstractize the configuration layer by introducing **configuration classes** which describe available parameters and their defaults. For [example](https://github.com/palkan/influxer/blob/master/lib/influxer/config.rb):
```ruby
module Influxer
- class Config < Anyway::Config
+ class Config < Runger::Config
attr_config(
host: "localhost",
username: "root",
password: "root"
)
@@ -73,11 +73,11 @@
Using Ruby classes to represent configuration allows you to add helper methods and computed parameters easily, makes the configuration **testable**.
The `runger_config` gem takes care of loading parameters from **different sources** (YAML, credentials/secrets, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality.
-Check out the libraries using Anyway Config for more examples:
+Check out the libraries using Runger Config for more examples:
- [Influxer](https://github.com/palkan/influxer)
- [AnyCable](https://github.com/anycable/anycable)
- [Sniffer](https://github.com/aderyabin/sniffer)
- [Blood Contracts](https://github.com/sclinede/blood_contracts)
@@ -113,17 +113,17 @@
### Configuration classes
Using configuration classes allows you to make configuration data a bit more than a bag of values:
you can define a schema for your configuration, provide defaults, add validations and additional helper methods.
-Anyway Config provides a base class to inherit from with a few DSL methods:
+Runger Config provides a base class to inherit from with a few DSL methods:
```ruby
require "runger_config"
module MyCoolGem
- class Config < Anyway::Config
+ class Config < Runger::Config
attr_config user: "root", password: "root", host: "localhost"
end
end
```
@@ -139,11 +139,11 @@
```ruby
MyCoolGem::Config.new.user #=> "root"
```
-**Bonus:**: if you define attributes with boolean default values (`false` or `true`), Anyway Config would automatically add a corresponding predicate method. For example:
+**Bonus:**: if you define attributes with boolean default values (`false` or `true`), Runger Config would automatically add a corresponding predicate method. For example:
```ruby
attr_config :user, :password, debug: false
MyCoolGem::Config.new.debug? #=> false
@@ -151,11 +151,11 @@
```
**NOTE**: since v2.0 accessors created by `attr_config` are not `attr_accessor`, i.e. they do not populate instance variables. If you used instance variables before to override readers, you must switch to using `super` or `values` store:
```ruby
-class MyConfig < Anyway::Config
+class MyConfig < Runger::Config
attr_config :host, :port, :url, :meta
# override writer to handle type coercion
def meta=(val)
super JSON.parse(val)
@@ -189,40 +189,40 @@
end
```
#### Config name
-Anyway Config relies on the notion of _config name_ to populate data.
+Runger Config relies on the notion of _config name_ to populate data.
-By default, Anyway Config uses the config class name to infer the config name using the following rules:
+By default, Runger Config uses the config class name to infer the config name using the following rules:
- if the class name has a form of `<Module>::Config` then use the module name (`SomeModule::Config => "somemodule"`)
- if the class name has a form of `<Something>Config` then use the class name prefix (`SomeConfig => "some"`)
**NOTE:** in both cases, the config name is a **downcased** module/class prefix, not underscored.
You can also specify the config name explicitly (it's required in cases when your class name doesn't match any of the patterns above):
```ruby
module MyCoolGem
- class Config < Anyway::Config
+ class Config < Runger::Config
config_name :cool
attr_config user: "root", password: "root", host: "localhost", options: {}
end
end
```
#### Customize env variable names prefix
-By default, Anyway Config uses upper-cased config name as a prefix for env variable names (e.g.
+By default, Runger Config uses upper-cased config name as a prefix for env variable names (e.g.
`config_name :my_app` will result to parsing `MY_APP_` prefix).
You can set env prefix explicitly:
```ruby
module MyCoolGem
- class Config < Anyway::Config
+ class Config < Runger::Config
config_name :cool_gem
env_prefix :really_cool # now variables, starting wih `REALLY_COOL_`, will be parsed
attr_config user: "root", password: "root", host: "localhost", options: {}
end
end
@@ -256,20 +256,20 @@
```ruby
# load data from config/my_app.yml,
# credentials.my_app, secrets.my_app (if using Rails), ENV["MY_APP_*"]
#
# Given MY_APP_VALUE=42
-config = Anyway::Config.for(:my_app)
+config = Runger::Config.for(:my_app)
config["value"] #=> 42
# you can specify the config file path or env prefix
-config = Anyway::Config.for(:my_app, config_path: "my_config.yml", env_prefix: "MYAPP")
+config = Runger::Config.for(:my_app, config_path: "my_config.yml", env_prefix: "MYAPP")
```
This feature is similar to `Rails.application.config_for` but more powerful:
-| Feature | Rails | Anyway Config |
+| Feature | Rails | Runger Config |
| ------------- |-------------:| -----:|
| Load data from `config/app.yml` | ✅ | ✅ |
| Load data from `secrets` | ❌ | ✅ |
| Load data from `credentials` | ❌ | ✅ |
| Load data from environment | ❌ | ✅ |
@@ -284,47 +284,47 @@
\* Make sure that ERB is loaded
### Validation and callbacks
-Anyway Config provides basic ways of ensuring that the configuration is valid.
+Runger Config provides basic ways of ensuring that the configuration is valid.
There is a built-in `required` class method to define the list of parameters that must be present in the
configuration after loading (where present means non-`nil` and non-empty for strings):
```ruby
-class MyConfig < Anyway::Config
+class MyConfig < Runger::Config
attr_config :api_key, :api_secret, :debug
required :api_key, :api_secret
end
-MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError
+MyConfig.new(api_secret: "") #=> raises Runger::Config::ValidationError
```
`Required` method supports additional `env` parameter which indicates necessity to run validations under specified
environments. `Env` parameter could be present in symbol, string, array or hash formats:
```ruby
-class EnvConfig < Anyway::Config
+class EnvConfig < Runger::Config
required :password, env: "production"
required :maps_api_key, env: :production
required :smtp_host, env: %i[production staging]
required :aws_bucket, env: %w[production staging]
required :anycable_rpc_host, env: {except: :development}
required :anycable_redis_url, env: {except: %i[development test]}
required :anycable_broadcast_adapter, env: {except: %w[development test]}
end
```
-If your current `Anyway::Settings.current_environment` is mismatch keys that specified
-`Anyway::Config::ValidationError` error will be raised.
+If your current `Runger::Settings.current_environment` is mismatch keys that specified
+`Runger::Config::ValidationError` error will be raised.
If you need more complex validation or need to manipulate with config state right after it has been loaded, you can use _on load callbacks_ and `#raise_validation_error` method:
```ruby
-class MyConfig < Anyway::Config
+class MyConfig < Runger::Config
attr_config :api_key, :api_secret, :mode
# on_load macro accepts symbol method names
on_load :ensure_mode_is_valid
@@ -346,11 +346,11 @@
## Using with Rails
**NOTE:** version 2.x supports Rails >= 5.0; for Rails 4.x use version 1.x of the gem.
We recommend going through [Data population](#data-population) and [Organizing configs](#organizing-configs) sections first,
-and then use [Rails generators](#generators) to make your application Anyway Config-ready.
+and then use [Rails generators](#generators) to make your application Runger Config-ready.
### Data population
Your config is filled up with values from the following sources (ordered by priority from low to high):
@@ -366,11 +366,11 @@
development:
host: localhost
port: 3000
```
-**NOTE:** You can override the environment name for configuration files via the `ANYWAY_ENV` environment variable or by setting it explicitly in the code: `Anyway::Settings.current_environment = "some_other_env"`.
+**NOTE:** You can override the environment name for configuration files via the `RUNGER_ENV` environment variable or by setting it explicitly in the code: `Runger::Settings.current_environment = "some_other_env"`.
### Multi-env configuration
_⚡️ This feature will be turned on by default in the future releases. You can turn it on now via `config.runger_config.future.use :unwrap_known_environments`._
@@ -395,17 +395,17 @@
host: localhost # This value will be loaded when Rails.env.staging? is true
port: 3002 # This value will not be loaded at all
```
-To provide default values you can use YAML anchors, but they do not deep-merge settings, so Anyway Config provides a way to define a special top-level key for default values like this:
+To provide default values you can use YAML anchors, but they do not deep-merge settings, so Runger Config provides a way to define a special top-level key for default values like this:
```ruby
config.runger_config.default_environmental_key = "default"
```
-After that, Anyway Config will start reading settings under the `"default"` key and then merge environmental settings into them.
+After that, Runger Config will start reading settings under the `"default"` key and then merge environmental settings into them.
```yml
default:
server: # This values will be loaded in all environments by default
host: localhost
@@ -441,11 +441,11 @@
development:
my_cool_gem:
port: 4444
```
-**NOTE:** If you want to use secrets with Rails 7.1 (still supported, but deprecated) you must add the corresponding loader manually: `Anyway.loaders.insert_after :yml, :secrets, Anyway::Rails::Loaders::Secrets`.
+**NOTE:** If you want to use secrets with Rails 7.1 (still supported, but deprecated) you must add the corresponding loader manually: `Runger.loaders.insert_after :yml, :secrets, Runger::Rails::Loaders::Secrets`.
3) **Rails credentials**: `Rails.application.credentials.my_cool_gem` (if supported):
```yml
my_cool_gem:
@@ -471,11 +471,11 @@
We have the following config to fetch the Heroku provided [metadata](https://devcenter.heroku.com/articles/dyno-metadata):
```ruby
# This data is provided by Heroku Dyno Metadadata add-on.
-class HerokuConfig < Anyway::Config
+class HerokuConfig < Runger::Config
attr_config :app_id, :app_name,
:dyno_id, :release_version,
:slug_commit
def hostname
@@ -516,95 +516,95 @@
end
```
### Generators
-Anyway Config provides Rails generators to create new config classes:
+Runger Config provides Rails generators to create new config classes:
-- `rails g anyway:install`—creates an `ApplicationConfig` class (the base class for all config classes) and updates `.gitignore`
+- `rails g runger:install`—creates an `ApplicationConfig` class (the base class for all config classes) and updates `.gitignore`
You can specify the static configs path via the `--configs-path` option:
```sh
-rails g anyway:install --configs-path=config/settings
+rails g runger:install --configs-path=config/settings
# or to keep everything in app/configs
-rails g anyway:install --configs-path=app/configs
+rails g runger:install --configs-path=app/configs
```
-- `rails g anyway:config <name> param1 param2 ...`—creates a named configuration class and optionally the corresponding YAML file; creates `application_config.rb` is missing.
+- `rails g runger:config <name> param1 param2 ...`—creates a named configuration class and optionally the corresponding YAML file; creates `application_config.rb` is missing.
The generator command for the Heroku example above would be:
```sh
-$ rails g anyway:config heroku app_id app_name dyno_id release_version slug_commit
+$ rails g runger:config heroku app_id app_name dyno_id release_version slug_commit
- generate anyway:install
- rails generate anyway:install
+ generate runger:install
+ rails generate runger:install
create config/configs/application_config.rb
append .gitignore
create config/configs/heroku_config.rb
Would you like to generate a heroku.yml file? (Y/n) n
```
You can also specify the `--app` option to put the newly created class into `app/configs` folder.
-Alternatively, you can call `rails g anyway:app_config name param1 param2 ...`.
+Alternatively, you can call `rails g runger:app_config name param1 param2 ...`.
-**NOTE:** The generated `ApplicationConfig` class uses a singleton pattern along with `delegate_missing_to` to re-use the same instance across the application. However, the delegation can lead to unexpected behaviour and break Anyway Config internals if you have attributes named as `Anyway::Config` class methods. See [#120](https://github.com/davidrunger/runger_config/issues/120).
+**NOTE:** The generated `ApplicationConfig` class uses a singleton pattern along with `delegate_missing_to` to re-use the same instance across the application. However, the delegation can lead to unexpected behaviour and break Runger Config internals if you have attributes named as `Runger::Config` class methods. See [#120](https://github.com/davidrunger/runger_config/issues/120).
-### Loading Anyway Config before Rails
+### Loading Runger Config before Rails
-Anyway Config activates Rails-specific features automatically on the gem load only if Rails has been already required (we check for the `Rails::VERSION` constant presence). However, in some cases you may want to use Anyway Config before Rails initialization (e.g., in `config/puma.rb` when starting a Puma web server).
+Runger Config activates Rails-specific features automatically on the gem load only if Rails has been already required (we check for the `Rails::VERSION` constant presence). However, in some cases you may want to use Runger Config before Rails initialization (e.g., in `config/puma.rb` when starting a Puma web server).
-By default, Anyway Config sets up a hook (via TracePoint API) and waits for Rails to be loaded to require the Rails extensions (`require "anyway/rails"`). In case you load Rails after Anyway Config, you will see a warning telling you about that. Note that config classes loaded before Rails are not populated from Rails-specific data sources (e.g., credentials).
+By default, Runger Config sets up a hook (via TracePoint API) and waits for Rails to be loaded to require the Rails extensions (`require "runger/rails"`). In case you load Rails after Runger Config, you will see a warning telling you about that. Note that config classes loaded before Rails are not populated from Rails-specific data sources (e.g., credentials).
-You can disable the warning by setting `Anyway::Rails.disable_postponed_load_warning = true` in your application. Also, you can disable the _hook_ completely by calling `Anyway::Rails.tracer.disable`.
+You can disable the warning by setting `Runger::Rails.disable_postponed_load_warning = true` in your application. Also, you can disable the _hook_ completely by calling `Runger::Rails.tracer.disable`.
## Using with Ruby
The default data loading mechanism for non-Rails applications is the following (ordered by priority from low to high):
1) **YAML configuration files**: `./config/<config-name>.yml`.
In pure Ruby apps, we also can load data under specific _environments_ (`test`, `development`, `production`, etc.).
-If you want to enable this feature you must specify `Anyway::Settings.current_environment` variable for load config under specific environment.
+If you want to enable this feature you must specify `Runger::Settings.current_environment` variable for load config under specific environment.
```ruby
-Anyway::Settings.current_environment = "development"
+Runger::Settings.current_environment = "development"
```
-You can also specify the `ANYWAY_ENV=development` environment variable to set the current environment for configuration.
+You can also specify the `RUNGER_ENV=development` environment variable to set the current environment for configuration.
YAML files should be in this format:
```yml
development:
host: localhost
port: 3000
```
-If `Anyway::Settings.current_environment` is missed we assume that the YAML contains values for a single environment:
+If `Runger::Settings.current_environment` is missed we assume that the YAML contains values for a single environment:
```yml
host: localhost
port: 3000
```
`ERB` is supported if `erb` is loaded (thus, you need to call `require "erb"` somewhere before loading configuration).
You can specify the lookup path for YAML files in one of the following ways:
-- By setting `Anyway::Settings.default_config_path` to a target directory path:
+- By setting `Runger::Settings.default_config_path` to a target directory path:
```ruby
-Anyway::Settings.default_config_path = "/etc/configs"
+Runger::Settings.default_config_path = "/etc/configs"
```
-- By setting `Anyway::Settings.default_config_path` to a Proc, which accepts a config name and returns the path:
+- By setting `Runger::Settings.default_config_path` to a Proc, which accepts a config name and returns the path:
```ruby
-Anyway::Settings.default_config_path = ->(name) { Rails.root.join("data", "configs", "#{name}.yml") }
+Runger::Settings.default_config_path = ->(name) { Rails.root.join("data", "configs", "#{name}.yml") }
```
- By overriding a specific config YML file path via the `<NAME>_CONF` env variable, e.g., `MYCOOLGEM_CONF=path/to/cool.yml`
2) **Environment variables**: `ENV['MYCOOLGEM_*']`.
@@ -624,11 +624,11 @@
- `"nil"` and `"null"` to `nil` (do you really need it?);
- `"123"` to `123` and `"3.14"` to `3.14`.
Type coercion can be [customized or disabled](#type-coercion).
-*Anyway Config* supports nested (_hashed_) env variables—just separate keys with double-underscore.
+*Runger Config* supports nested (_hashed_) env variables—just separate keys with double-underscore.
For example, "MYCOOLGEM_OPTIONS__VERBOSE" is parsed as `config.options["verbose"]`.
Array values are also supported:
@@ -648,11 +648,11 @@
> 🆕 v2.2.0
You can define custom type coercion rules to convert string data to config values. To do that, use `.coerce_types` method:
```ruby
-class CoolConfig < Anyway::Config
+class CoolConfig < Runger::Config
config_name :cool
attr_config port: 8080,
host: "localhost",
user: {name: "admin", password: "admin"}
@@ -689,11 +689,11 @@
```
Finally, it's possible to disable auto-casting for a particular config completely:
```ruby
-class CoolConfig < Anyway::Config
+class CoolConfig < Runger::Config
attr_config port: 8080,
host: "localhost",
user: {name: "admin", password: "admin"}
disable_auto_cast!
@@ -720,11 +720,11 @@
when "blue"
"#0000ff"
end
end
-class CoolConfig < Anyway::Config
+class CoolConfig < Runger::Config
attr_config :color
coerce_types color: COLOR_TO_HEX
end
@@ -741,11 +741,11 @@
- `config/credentials/local.yml.enc` (for Rails >= 6, generate it via `rails credentials:edit --environment local`).
\* If the YAML config path is not a default one (i.e., set via `<CONFIG_NAME>_CONF`), we look up the local
config at this location, too.
-Local configs are meant for using in development and only loaded if `Anyway::Settings.use_local_files` is `true` (which is true by default if `RACK_ENV` or `RAILS_ENV` env variable is equal to `"development"`).
+Local configs are meant for using in development and only loaded if `Runger::Settings.use_local_files` is `true` (which is true by default if `RACK_ENV` or `RAILS_ENV` env variable is equal to `"development"`).
**NOTE:** in Rails apps you can use `Rails.application.configuration.runger_config.use_local_files`.
Don't forget to add `*.local.yml` (and `config/credentials/local.*`) to your `.gitignore`.
@@ -753,28 +753,28 @@
## Data loaders
### Doppler integration
-Anyway Config can pull configuration data from [Doppler](https://www.doppler.com/). All you need is to specify the `DOPPLER_TOKEN` environment variable with the **service token**, associated with the specific content (read more about [service tokens](https://docs.doppler.com/docs/service-tokens)).
+Runger Config can pull configuration data from [Doppler](https://www.doppler.com/). All you need is to specify the `DOPPLER_TOKEN` environment variable with the **service token**, associated with the specific content (read more about [service tokens](https://docs.doppler.com/docs/service-tokens)).
You can also configure Doppler loader manually if needed:
```ruby
# Add loader
-Anyway.loaders.append :Doppler, Anyway::Loaders::Doppler
+Runger.loaders.append :Doppler, Runger::Loaders::Doppler
# Configure API URL and token (defaults are shown)
-Anyway::Loaders::Doppler.download_url = "https://api.doppler.com/v3/configs/config/secrets/download"
-Anyway::Loaders::Doppler.token = ENV["DOPPLER_TOKEN"]
+Runger::Loaders::Doppler.download_url = "https://api.doppler.com/v3/configs/config/secrets/download"
+Runger::Loaders::Doppler.token = ENV["DOPPLER_TOKEN"]
```
-**NOTE:** You can opt-out from Doppler loader by specifying the`ANYWAY_CONFIG_DISABLE_DOPPLER=true` env var (in case you have the `DOPPLER_TOKEN` env var, but don't want to use it with Anyway Config).
+**NOTE:** You can opt-out from Doppler loader by specifying the`RUNGER_CONFIG_DISABLE_DOPPLER=true` env var (in case you have the `DOPPLER_TOKEN` env var, but don't want to use it with Runger Config).
### EJSON support
-Anyway Config allows you to keep your configuration also in encrypted `.ejson` files. More information
+Runger Config allows you to keep your configuration also in encrypted `.ejson` files. More information
about EJSON format you can read [here](https://github.com/Shopify/ejson).
Configuration will be loaded only if you have `ejson` executable in your PATH. Easiest way to do this - install `ejson` as a gem into project:
```ruby
@@ -808,11 +808,11 @@
```
You can customize the JSON namespace under which a loader searches for configuration via `loader_options`:
```ruby
-class MyConfig < Anyway::Config
+class MyConfig < Runger::Config
# To look under the key "foo" instead of the default key of "my"
loader_options ejson_namespace: "foo"
# Or to disable namespacing entirely, and instead search in the root object
loader_options ejson_namespace: false
@@ -823,14 +823,14 @@
You can provide your own data loaders or change the existing ones using the Loaders API (which is very similar to Rack middleware builder):
```ruby
# remove env loader => do not load params from ENV
-Anyway.loaders.delete :env
+Runger.loaders.delete :env
# add custom loader before :env (it's better to keep the ENV loader the last one)
-Anyway.loaders.insert_before :env, :my_loader, MyLoader
+Runger.loaders.insert_before :env, :my_loader, MyLoader
```
Loader is a _callable_ Ruby object (module/class responding to `.call` or lambda/proc), which `call` method
accepts the following keyword arguments:
@@ -838,17 +838,17 @@
def call(
name:, # config name
env_prefix:, # prefix for env vars if any
config_path:, # path to YML config
local:, # true|false, whether to load local configuration
- **options # custom options can be passed via Anyway::Config.loader_options example: "custom", option: "blah"
+ **options # custom options can be passed via Runger::Config.loader_options example: "custom", option: "blah"
)
#=> must return Hash with configuration data
end
```
-You can use `Anyway::Loaders::Base` as a base class for your loader and define a `#call` method.
+You can use `Runger::Loaders::Base` as a base class for your loader and define a `#call` method.
For example, the [Chamber](https://github.com/thekompanee/chamber) loader could be written as follows:
```ruby
class ChamberConfigLoader < Base
def call(name:, **_opts)
@@ -858,11 +858,11 @@
{}
end
end
# Don't forget to register it
-Anyway.loaders.insert_before :env, :chamber, ChamberConfigLoader
+Runger.loaders.insert_before :env, :chamber, ChamberConfigLoader
```
In order to support [source tracing](#tracing), you need to wrap the resulting Hash via the `#trace!` method with metadata:
```ruby
@@ -876,13 +876,13 @@
end
```
## Tracing
-Since Anyway Config loads data from multiple source, it could be useful to know where a particular value came from.
+Since Runger Config loads data from multiple source, it could be useful to know where a particular value came from.
-Each `Anyway::Config` instance contains _tracing information_ which you can access via `#to_source_trace` method:
+Each `Runger::Config` instance contains _tracing information_ which you can access via `#to_source_trace` method:
```ruby
conf = ExampleConfig.new
conf.to_source_trace
@@ -897,16 +897,16 @@
}
# if you change the value manually in your code,
# that would be reflected in the trace
-conf.host = "anyway.host"
+conf.host = "runger.host"
conf.to_source_trace["host"]
#=> {type: :user, called_from: "/path/to/caller.rb:15"}
```
-You can disable tracing functionality by setting `Anyway::Settings.tracing_enabled = false` or `config.runger_config.tracing_enabled = false` in Rails.
+You can disable tracing functionality by setting `Runger::Settings.tracing_enabled = false` or `config.runger_config.tracing_enabled = false` in Rails.
### Pretty print
You can use `pp` to print a formatted information about the config including the sources trace.
@@ -984,21 +984,21 @@
If you want to delete the env var, pass `nil` as the value.
This helper is automatically included to RSpec if `RAILS_ENV` or `RACK_ENV` env variable is equal to "test". It's only available for the example with the tag `type: :config` or with the path `spec/configs/...`.
-You can add it manually by requiring `"anyway/testing/helpers"` and including the `Anyway::Testing::Helpers` module (into RSpec configuration or Minitest test class).
+You can add it manually by requiring `"runger/testing/helpers"` and including the `Runger::Testing::Helpers` module (into RSpec configuration or Minitest test class).
## OptionParser integration
It's possible to use config as option parser (e.g., for CLI apps/libraries). It uses
[`optparse`](https://ruby-doc.org/stdlib-2.5.1/libdoc/optparse/rdoc/OptionParser.html) under the hood.
Example usage:
```ruby
-class MyConfig < Anyway::Config
+class MyConfig < Runger::Config
attr_config :host, :log_level, :concurrency, :debug, server_args: {}
# specify which options shouldn't be handled by option parser
ignore_options :server_args
@@ -1050,11 +1050,11 @@
)
```
## RBS support
-Anyway Config comes with Ruby type signatures (RBS).
+Runger Config comes with Ruby type signatures (RBS).
To use them with Steep, add the following your `Steepfile`:
```ruby
library "pathname"
@@ -1063,11 +1063,11 @@
```
We also provide an API to generate a type signature for your config class:
```ruby
-class MyGem::Config < Anyway::Config
+class MyGem::Config < Runger::Config
attr_config :host, port: 8080, tags: [], debug: false
coerce_types host: :string, port: :integer,
tags: {type: :string, array: true}
@@ -1089,21 +1089,21 @@
def debug: () -> bool
def debug?: () -> bool
def debug=: (bool) -> void
end
- class Config < Anyway::Config
+ class Config < Runger::Config
include _Config
end
end
```
### Handling `on_load`
When we use `on_load` callback with a block, we switch the context (via `instance_eval`), and we need to provide type hints for the type checker. Here is an example:
```ruby
-class MyConfig < Anyway::Config
+class MyConfig < Runger::Config
on_load do
# @type self : MyConfig
raise_validation_error("host is invalid") if host.start_with?("localhost")
end
end