diff options
author | Adam Jacob <adam@hjksolutions.com> | 2008-04-07 18:14:25 -0700 |
---|---|---|
committer | Adam Jacob <adam@hjksolutions.com> | 2008-04-07 18:14:25 -0700 |
commit | 434f25ba07b5c0c50baa1e15b14a945bba3c3c3b (patch) | |
tree | 03085c689549a62d546d87e6484dde8756da2d23 /lib/chef/node.rb | |
parent | f543b509ba61dd347512e8a9e3153a49a2a8cb6b (diff) | |
download | chef-434f25ba07b5c0c50baa1e15b14a945bba3c3c3b.tar.gz |
Adding the Params::Validate mixin, refactored Chef::Config to be a singleton, Implemented require_recipe
Diffstat (limited to 'lib/chef/node.rb')
-rw-r--r-- | lib/chef/node.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 69dc6ab3f0..d5896fbd95 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -1,4 +1,7 @@ # +# Chef::Node +# +# # Author:: Adam Jacob (<adam@hjksolutions.com>) # Copyright:: Copyright (c) 2008 HJK Solutions, LLC # License:: GNU General Public License version 2 or later @@ -29,12 +32,14 @@ class Chef include Chef::Mixin::CheckHelper include Chef::Mixin::FromFile + # Create a new Chef::Node object. def initialize() @name = nil @attribute = Hash.new @recipe_list = Array.new end + # Set the name of this Node, or return the current name. def name(arg=nil) set_if_args(@name, arg) do |a| case a @@ -46,6 +51,7 @@ class Chef end end + # Return an attribute of this node. Returns nil if the attribute is not found. def [](attrib) if @attribute.has_key?(attrib) @attribute[attrib] @@ -56,6 +62,15 @@ class Chef end end + # Iterates over each attribute, passing the attribute and value to the block. + def each_attribute(&block) + @attribute.each do |k,v| + yield(k, v) + end + end + + # Return true if this Node has a given attribute, false if not. Takes either a symbol or + # a string. def attribute?(attrib) result = false result = @attribute.has_key?(attrib) @@ -63,10 +78,13 @@ class Chef return @attribute.has_key?(attrib.to_sym) end + # Returns true if this Node expects a given recipe, false if not. def recipe?(recipe_name) @recipe_list.detect { |r| r == recipe_name } ? true : false end + # Returns an Array of recipes. If you call it with arguments, they will become the new + # list of recipes. def recipes(*args) if args.length > 0 @recipe_list = args.flatten @@ -75,6 +93,9 @@ class Chef end end + # Set an attribute based on the missing method. If you pass an argument, we'll use that + # to set the attribute values. Otherwise, we'll wind up just returning the attributes + # value. def method_missing(symbol, *args) if args.length != 0 @attribute[symbol] = args.length == 1 ? args[0] : args |