Method: NewRelic::Agent::AttributeProcessing.flatten_and_coerce_hash

Defined in:
lib/new_relic/agent/attribute_processing.rb

.flatten_and_coerce_hash(hash, prefix, result, &blk) ⇒ Object

[View source]

31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/new_relic/agent/attribute_processing.rb', line 31

def flatten_and_coerce_hash(hash, prefix, result, &blk)
  if hash.empty?
    if blk
      yield(prefix, EMPTY_HASH_STRING_LITERAL)
    else
      result[prefix] = EMPTY_HASH_STRING_LITERAL
    end
  else
    hash.each do |key, val|
      next_prefix = prefix ? "#{prefix}.#{key}" : key.to_s
      flatten_and_coerce(val, next_prefix, result, &blk)
    end
  end
end