Module: Fluent::FlattenHashUtil

Included in:
Plugin::FlattenHashFilter, Plugin::FlattenHashOutput
Defined in:
lib/fluent/plugin/flatten_hash_util.rb

Instance Method Summary collapse

Instance Method Details

#flatten_record(record, prefix) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fluent/plugin/flatten_hash_util.rb', line 3

def flatten_record(record, prefix)
  ret = {}
  if record.is_a? Hash
    record.each { |key, value|
      ret.merge! flatten_record(value, prefix + [key.to_s])
    }
  elsif record.is_a? Array
    if @flatten_array
      record.each_with_index { |elem, index|
        ret.merge! flatten_record(elem, prefix + [index.to_s])
      }
    else
      return {prefix.join(@separator) => record}
    end
  else
    return {prefix.join(@separator) => record}
  end
  ret
end