Created
May 16, 2009 00:09
-
-
Save aymerick/112509 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
# | |
# /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