rubyconfig / config

Easiest way to add multi-environment yaml settings to Rails, Sinatra, Padrino and other Ruby projects.
Other
2.11k stars 231 forks source link

Is it possible to reference another configuration in a YAML file? #302

Closed pecuerre closed 3 years ago

pecuerre commented 3 years ago

Let me explain. I think the title might not be clear.

I would like to do something like:

color:
  front: '000000'
  back: 'FFFFFF'
text:
  size: 10
  family: Arial
  color: <%= Settings.color.front %> # or some similar syntax

but when I put this it says uninitialized constant Settings.

is it possible to do that? is it a workaround some how?

basically what i want to do is define one value that depends on another value.

cjlarose commented 3 years ago

YAML itself has support for anchors and references, so in your case you can do something like this:

color:
  front: &front-color '000000'
  back: 'FFFFFF'
text:
  size: 10
  family: Arial
  color: *front-color

See the YAML 1.2 specification section 6.9.2 for more details

pecuerre commented 3 years ago

Oh, thanks. It didn't occurred to me to look in the YAML documentation.