Last active
May 4, 2017 18:14
-
-
Save elorest/f46938a0548eb286b9d796b89a36f5e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro parse_yaml(filename) | |
{{ run("./yamlparser.cr", filename) }} | |
end | |
parse_yaml("tmp.yml") | |
puts dev["array"] | |
puts prod["array"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prod: | |
string: "foobar" | |
array: | |
- John | |
- Clara | |
hash: {key: value} | |
paragraph: | | |
foo | |
bar | |
dev: | |
string: "moobar" | |
array: | |
- Riley | |
- Sarah | |
hash: {key: value} | |
paragraph: | | |
moo | |
bar | |
test: | |
string: "testbar" | |
array: | |
- Wren | |
- Shauna | |
hash: {key: value} | |
paragraph: | | |
test | |
bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "yaml" | |
if ARGV[0]? | |
yml = YAML.parse(File.read(ARGV[0])) | |
str = yml.as_h.keys.map do |k| | |
String.build do |s| | |
s << "def #{k}\n " | |
s << yml[k.to_s].as_h.inspect | |
s << "\nend" | |
end | |
end.join("\n\n") | |
puts str | |
else | |
puts "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment