Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aymerick/112509 to your computer and use it in GitHub Desktop.
Save aymerick/112509 to your computer and use it in GitHub Desktop.
#
# /my_recipe/librairies/shared.rb
#
class Chef
class Recipe
# Fill an attribute with given hash
def attribute_from_hash(hash)
attribute = Mash.new
hash.each do |key, value|
if value.is_a?(Hash)
attribute[key] = attribute_from_hash(value) unless attribute.has_key?(key)
else
attribute[key] = value unless attribute.has_key?(key)
end
end
attribute
end
end # class Recipe
end # class Chef
#
# /my_recipe/attributes/my_recipe.rb
#
my_recipe attribute_from_hash(
:foo => "bar,
:amqp => {
:user => "user"
:pass => "pass",
:vhost => "/vhost",
:host => "localhost",
:port => "5672",
},
:couchdb => {
:host => "localhost",
:port => "5984",
:url => "http://127.0.0.1:5984",
:database => "pouet",
},
:xmpp => {
:host => "localhost",
:port => "5222",
:user => "user",
:password => "pass",
},
) unless attribute?(:my_recipe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment