I have a sample yaml file(abc.yaml) like this:
entity1:
condition: "created_at >= #{Date.today - 3.months}"
I want to read this condition from YAML in Ruby as :
"created_at >= 2015-03-02"
But when I do
YAML.load_file('abc.yaml')["entity1"]["condition"]
I get:
"created_at >= \#{Date.today - 3.months}"
Please let me know how to work around this.
The safer option would be to only convert known data from a pre-determined format. Or use something cool like settingslogic https://github.com/settingslogic/settingslogic. It uses ERB-style formatting to load settings, so you get some built in safety.
eg:
defaults: &defaults
cool:
saweet: nested settings
neat_setting: 24
awesome_setting: <%= "Did you know 5 + 5 = #{5 + 5}?" %>
Do this only if you're absolutely sure nobody can change your yaml file to inject something harmful:
condition = YAML.load_file('abc.yaml')["entity1"]["condition"]
condition = eval "\"#{condition}\""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With