-
-
Notifications
You must be signed in to change notification settings - Fork 25
File Layout
If you're just starting out, you don't really need to worry about this
information. I'd recommend just using a settings.yml
file.
When you chamber init
, you'll get a settings.yml
file which is typically
dropped in the correct location so that when Chamber is loaded, it picks it up
automatically.
Once your settings.yml
starts getting unwieldy, you can feel free to come back
here and see the different ways you can break your settings up to make them more
organized.
Ok, so your settings.yml
is starting to get a little too crazy for your
tastes. And now you may be wondering how to wrangle it into something more
managable.
Chamber gives you plenty of options.
Let's take a look at an example which contains a lot of Chamber's different file nameing and layout options:
<basepath>/settings
|
|-- email
| |
| |-- addresses.yml
| |-- smtp
| |
| |-- servers.yml
| |-- servers-myhostname.yml
| |-- servers-production.yml
|
|-- http
| |
| |-- main.yml
| |-- webclient.yml
|
|-- sidekiq
| |
| |-- main.yml.erb
| |-- queues.yml
|
|-- redis.yml.erb
|-- redis.test.yml
|-- settings.yml.erb
|-- stripe.yml.erb
Hint: it doesn't.
As far as Chamber is concerned, the structure of your files has no bearing on
how you access the contents of those files. They are for your organizational
purposes only. You could create a file named servers.yml
that had this
content:
stripe:
api_key: 'mykey'
And Chamber doesn't care. It'll happily serve up mykey
if you ask it for
Chamber.dig!('stripe', 'api_key')
.
This makes Chamber extremely flexible. You can lay your files out however works
best for your project. Now, granted, the above example seems kind of dumb, but
what if you had a servers.yml
and wanted to do this?
redis:
url: 'redis://localhost:9876'
smtp:
url: 'https://cache.example.com'
database:
url: 'https://db.example.com'
You could access these as you'd expect:
Chamber.dig!('redis', 'url')
Chamber.dig!('smtp', 'url')
Chamber.dig!('database', 'url')
Now this starts to make a bit more sense. Do I do this? No. But everyone thinks differently and if this organization makes more sense for you, Chamber will let you do it.
For full information on ERB preprocessing, check out the full guide
here but I just want to note here that your filename does
not have to end in .erb
to be run through ERB. Every file is run through
it. Having the .yml.erb
extension can just make it easier for editors to
syntax highlight properly.
You'll notice in the above example that some of the files have things like
production
and test
and myhostname
in them. What are these weird-looking
filenames? You can find a full description here.
Next Step: Defining Settings
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