Skip to content

Accessing Settings

Jeff Felchner edited this page Jan 9, 2018 · 7 revisions

Just Getting Started?

No problem. Chamber gives you an object to access your settings. You can start with Chamber.env.

Flat

So if you have a settings.yml with the following content:

# settings.yml

smtp_username: 'my_username'
smtp_password: 'my_password'
Chamber.env.smtp_username
# => 'my_username'

Nested

Or if you have nested settings, you'd separate each level with a ..

# settings.yml

smtp:
  username: 'my_username'
  password: 'my_password'
Chamber.env.smtp.username
# => 'my_username'

Hash

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'

Secure Settings

We'll talk about this more when we discuss securing 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.env.smtp.password
# => 'my_password'

Note: The entirety of the Wiki will use object notation for consistency.

Clone this wiki locally