rubyconfig / config

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

Preserve newlines while using embedded Ruby #312

Closed matteo-rossi-wise closed 2 years ago

matteo-rossi-wise commented 2 years ago

👋🏻 Hi all, I'm facing an issue when I try to add a multiline string (OPENSSH Key) from an ENV variable. I'd expect my Settings.my_key to preserve newlines but they are removed instead, as follows:

Example 1: string w/ newline and w/o quotes

# config/settings.yml
# value passed from ENV["MY_KEY"]
my_key: <%= "my\nvalue" %>

Please note that YAML must be consistently indented using spaces. Tabs are not allowed.
Error: (<unknown>): could not find expected ':' while scanning a simple key at line 2 column 1 (RuntimeError)

Example 2: string w/ newline and w/ quotes

# config/settings.yml
# value passed from ENV["MY_KEY"]
my_key: '<%= "my\nvalue" %>'

irb(main):001:0> Settings.my_key
=> "my value"

Is there any built-in support for this scenario? Thanks 🙏🏻

cjlarose commented 2 years ago

Take a look at https://github.com/rubyconfig/config/issues/304#issuecomment-888489198

I think that was a very similar situation as your own.

matteo-rossi-wise commented 2 years ago

Thanks @cjlarose, I've decided to access the specific ENV variable directly instead of enabling global config use_env since I needed to access only one multiline string.

We can close this issues, thanks for the support 😃