Object
Flattens and expands nested Hashes representing Chef objects (e.g, Nodes, Roles, DataBagItems, etc.) into flat Hashes so the objects are suitable to be saved into Solr. This code is more or less copy-pasted from chef/solr/index which may or may not be a great idea, though that does minimize the dependencies and hopefully minimize the memory use of chef-expander.
# File lib/chef/expander/flattener.rb, line 72 def add_field_value(keys, value) value = value.to_s @flattened_item[keys.join(UNDERSCORE)] << value @flattened_item[keys.last] << value end
# File lib/chef/expander/flattener.rb, line 47 def flatten_and_expand @flattened_item = Hash.new {|hash, key| hash[key] = []} @item.each do |key, value| flatten_each([key.to_s], value) end @flattened_item.each_value { |values| values.uniq! } @flattened_item end
# File lib/chef/expander/flattener.rb, line 58 def flatten_each(keys, values) case values when Hash values.each do |child_key, child_value| add_field_value(keys, child_key) flatten_each(keys + [child_key.to_s], child_value) end when Array values.each { |child_value| flatten_each(keys, child_value) } else add_field_value(keys, values) end end
Generated with the Darkfish Rdoc Generator 2.