Skip to content

Instantly share code, notes, and snippets.

@keymon
Forked from saliceti/val_from_yaml.rb
Created October 1, 2015 15:50
Show Gist options
  • Save keymon/e8efd7af5f5dc58019ad to your computer and use it in GitHub Desktop.
Save keymon/e8efd7af5f5dc58019ad to your computer and use it in GitHub Desktop.
Extract a value from a YAML file
#!/usr/bin/env ruby
require 'yaml'
filename = ARGV[0]
path = ARGV[1]
def get(hash, path_array)
unless path_array.empty?
get(hash[path_array[0]], path_array[1..-1])
else
hash
end
end
secrets_hash = YAML.load_file(filename)
path_array = path.split('/')
puts get(secrets_hash, path_array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment