Sorry, I am not sure why I did not notice this before.

Could you use Ruby string interpolation instead of `+`? E.g. `#{Shellwords.shellescape(config['database'])}` instead of `" + Shellwords.shellescape(config['database']) + "`.