Class: ChefDK::Policyfile::AttributeMergeChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile/attribute_merge_checker.rb

Defined Under Namespace

Classes: AttributeHashInfo, ConflictError, Leaf

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeMergeChecker

Returns a new instance of AttributeMergeChecker.



62
63
64
# File 'lib/chef-dk/policyfile/attribute_merge_checker.rb', line 62

def initialize
  @attribute_hash_infos = []
end

Instance Attribute Details

#attribute_hash_infosArray<AttributeHashInfo> (readonly)

Returns A list of attributes and who they were provided by.

Returns:



60
61
62
# File 'lib/chef-dk/policyfile/attribute_merge_checker.rb', line 60

def attribute_hash_infos
  @attribute_hash_infos
end

Instance Method Details

#check!Object

Check all added attributes for conflicts. Different sources can provide the same attribute if they have the same value. Otherwise, it is considered a conflict

Raises:

  • ConflictError if there are conflicting attributes



80
81
82
83
84
85
# File 'lib/chef-dk/policyfile/attribute_merge_checker.rb', line 80

def check!
  check_struct = Mash.new
  attribute_hash_infos.each do |attr_hash_info|
    fill!(check_struct, attr_hash_info.source_name, "", attr_hash_info.hash)
  end
end

#with_attributes(source_name, hash) ⇒ Object

Add a hash of attributes to the set of attributes that will be compared for conflicts

Parameters:

  • source_name (String)

    Where the attributes came from

  • hash (Hash)

    attributes from source_name



71
72
73
# File 'lib/chef-dk/policyfile/attribute_merge_checker.rb', line 71

def with_attributes(source_name, hash)
  attribute_hash_infos << AttributeHashInfo.new(source_name, hash)
end