Created
April 30, 2013 20:06
-
-
Save willkelly/5491522 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
# This file autogenerated by Chef | |
# Do not edit; changes will be overridden. | |
# Instead, edit node["keystone"]["configuration"] | |
<%= | |
content = '' | |
# Normally sort isn't safe on hashes, as symbols do not sort. | |
# In this case, we know that the content has been converted two and from json | |
# and will have only string keys. | |
@config.sort.each do |name, subconfig| | |
if not subconfig.respond_to? "to_hash" | |
# no top level config allowed, ignore non-hashes. | |
next | |
end | |
section = "[#{name}]\n" | |
subconfig.sort.each do |k, v| | |
# key must be a string and value must be non-nil | |
if k.class != String or v.nil? | |
next | |
end | |
case v | |
when Array | |
v.each do |i| | |
section += "#{k}=#{i}\n" | |
end | |
when Hash | |
first = true | |
if v.length == 0 | |
next | |
end | |
section += "#{k}=" | |
v.sort.each do |key,value| | |
if first | |
first = false | |
else | |
section += "," | |
end | |
section += "#{key}:#{value}" | |
end | |
section +="\n" | |
when TrueClass | |
section += "#{k}=T\n" | |
when FalseClass | |
section += "#{k}=F\n" | |
else | |
section += "#{k}=#{v}\n" | |
end | |
if k == "DEFAULT" | |
#special case default | |
content = "#{section}\n#{content}" | |
else | |
content = "#{content}\n#{section}" | |
end | |
section = "" | |
end | |
end | |
content | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment