Class: Chef::Node
Overview
Slap some dandy handy methods to stick on a node.
Instance Method Summary collapse
-
#get(*keys) { ... } ⇒ Object
(also: #deep_fetch)
Recursively searchs a nested datastructure for a key and returns the value.
-
#has_recipe?(recipe) ⇒ TrueClass, FalseClass
(also: #include_recipe?, #includes_recipe?)
Boolean to check if a recipe is loaded in the run list.
-
#in?(environment) ⇒ Boolean
Determine if the current node is in the given Chef environment (or matches the given regular expression).
Instance Method Details
#get(*keys) { ... } ⇒ Object Also known as: deep_fetch
Recursively searchs a nested datastructure for a key and returns the value. If a block is provided its value will be returned if the key does not exist, otherwise UndefinedAttributeError is raised.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/garcon/chef/node.rb', line 67 def get(*keys, &block) keys.reduce(self) do |obj, key| begin key = Integer(key) if obj.is_a? Array obj.fetch(key) rescue ArgumentError, IndexError, NoMethodError break block.call(key) if block raise UndefinedAttributeError end end end |
#has_recipe?(recipe) ⇒ TrueClass, FalseClass Also known as: include_recipe?, includes_recipe?
Boolean to check if a recipe is loaded in the run list.
35 36 37 |
# File 'lib/garcon/chef/node.rb', line 35 def has_recipe?(recipe) loaded_recipes.include?(with_default(recipe)) end |
#in?(environment) ⇒ Boolean
Determine if the current node is in the given Chef environment (or matches the given regular expression).
49 50 51 |
# File 'lib/garcon/chef/node.rb', line 49 def in?(environment) environment === chef_environment end |