-
-
Notifications
You must be signed in to change notification settings - Fork 25
Accessing Settings
Jeff Felchner edited this page Mar 6, 2023
·
7 revisions
No problem. Chamber gives you an object to access your settings. You can start
with Chamber.dig!
.
So if you have a settings.yml
with the following content:
# settings.yml
smtp_username: 'my_username'
smtp_password: 'my_password'
Chamber.dig!('smtp_username')
# => 'my_username'
Or if you have nested settings, you'd separate each level with a .
.
# settings.yml
smtp:
username: 'my_username'
password: 'my_password'
Chamber.dig!('smtp', 'username')
# => 'my_username'
Lastly, you can access either flat or nested settings using Hash notation, which may make it easier if the setting you wish to access is dynamic.
# settings.yml
smtp:
username: 'my_smtp_username'
password: 'my_smtp_password'
redis:
username: 'my_redis_username'
password: 'my_redis_password'
class UsernameFinder
def self.username(service)
Chamber[service][:username]
end
end
UsernameFinder.username(:smtp)
# => 'my_smtp_username'
We'll talk about this more when we discuss
encrypting your settings but just
a heads up that if you have a setting that contains a _secure_
prefix, that
prefix is omitted when you access it.
# settings.yml
smtp:
username: 'my_username'
_secure_password: 'my_password'
Chamber.dig!('smtp', 'password')
# => 'my_password'
Next Step: Namespace Basics
Learn More:
Copyright ©2023
- Release News
- Gem Comparison
- 12-Factor App Rebuttal
- Environment Variable Problems
- Installation
- Basics
- Defining Settings
- Accessing Settings
- Verifying Settings
- Namespaces
- Environment Variables
- Integrations
- Encryption
- Advanced Usage
- Command Line Reference