README.md in anyway_config-2.5.2 vs README.md in anyway_config-2.5.3
- old
+ new
@@ -432,19 +432,21 @@
config.anyway_config.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) **Rails secrets**: `Rails.application.secrets.my_cool_gem` (if `secrets.yml` present).
+2) (Rails <7.1) **Rails secrets**: `Rails.application.secrets.my_cool_gem` (if `secrets.yml` present).
```yml
# config/secrets.yml
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`.
+
3) **Rails credentials**: `Rails.application.credentials.my_cool_gem` (if supported):
```yml
my_cool_gem:
host: secret.host
@@ -846,22 +848,31 @@
You can use `Anyway::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 < Anyway::Loaders::Base
+class ChamberConfigLoader < Base
def call(name:, **_opts)
- Chamber.env.to_h[name] || {}
+ Chamber.to_hash[name] || {}
+ rescue Chamber::Errors::DecryptionFailure => e
+ warn "Couldn't decrypt Chamber settings: #{e.message}"
+ {}
end
end
+
+# Don't forget to register it
+Anyway.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
def call(name:, **_opts)
trace!(:chamber) do
- Chamber.env.to_h[name] || {}
+ Chamber.to_hash[name] || {}
+ rescue Chamber::Errors::DecryptionFailure => e
+ warn "Couldn't decrypt Chamber settings: #{e.message}"
+ {}
end
end
```
## Tracing