Skip to content

Instantly share code, notes, and snippets.

@ckoparkar
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckoparkar/7b341028230e8f6ad051 to your computer and use it in GitHub Desktop.
Save ckoparkar/7b341028230e8f6ad051 to your computer and use it in GitHub Desktop.
Add all keys from yaml file to consul
require 'yaml'
require 'diplomat'
RAILS_ENV = ARGV[0]
x = YAML.load_file ARGV[1]
y = x.reduce({}) do |acc, (k, v)|
o = "#{RAILS_ENV}/#{k.downcase}"
if v.is_a? Hash
if k == RAILS_ENV
z = v.reduce({}) do |q, (r, s)|
t = "#{RAILS_ENV}/#{r.downcase}"
acc[t] = s
acc
end
else
acc
end
else
acc[o] = v
end
acc
end
y.each {|k,v| Diplomat.put(k, v.to_s)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment