Class: Chef::Node

Inherits:
Object show all
Defined in:
lib/garcon/chef/node.rb

Overview

Slap some dandy handy methods to stick on a node.

Instance Method Summary collapse

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.

Parameters:

Yields:

  • optional block to execute if no value is found

Returns:

Raises:

  • UndefinedAttributeError



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.

Parameters:

  • recipe (String)

    the command to find

Returns:



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).

Parameters:

Returns:



49
50
51
# File 'lib/garcon/chef/node.rb', line 49

def in?(environment)
  environment === chef_environment
end