Module: Chef::Mixin::LanguageIncludeAttribute

Included in:
Node
Defined in:
lib/chef/mixin/language_include_attribute.rb

Instance Method Summary collapse

Instance Method Details

#include_attribute(*fully_qualified_attribute_short_filenames) ⇒ Object

Loads the attribute file specified by the short name of the file, e.g., loads specified cookbook's

"attributes/mailservers.rb"

if passed

"mailservers"

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/mixin/language_include_attribute.rb', line 30

def include_attribute(*fully_qualified_attribute_short_filenames)
  if self.kind_of?(Chef::Node)
    node = self
  else
    node = @node
  end

  fully_qualified_attribute_short_filenames.flatten.each do |fully_qualified_attribute_short_filename|
    if node.run_state[:seen_attributes].has_key?(fully_qualified_attribute_short_filename)
      Chef::Log.debug("I am not loading attribute file #{fully_qualified_attribute_short_filename}, because I have already seen it.")
      next
    end

    Chef::Log.debug("Loading Attribute #{fully_qualified_attribute_short_filename}")
    node.run_state[:seen_attributes][fully_qualified_attribute_short_filename] = true

    if amatch = fully_qualified_attribute_short_filename.match(/(.+?)::(.+)/)
      cookbook_name = amatch[1].to_sym
      node.load_attribute_by_short_filename(amatch[2], cookbook_name)
    else
      cookbook_name = fully_qualified_attribute_short_filename.to_sym
      node.load_attribute_by_short_filename("default", cookbook_name)
    end
  end
  true
end