Class: RecordExploder
- Inherits:
-
Object
- Object
- RecordExploder
- Defined in:
- lib/fluent/plugin/record_exploder.rb
Instance Method Summary collapse
- #explode_record(keys, record) ⇒ Object
-
#initialize(values_retriever) ⇒ RecordExploder
constructor
A new instance of RecordExploder.
Constructor Details
#initialize(values_retriever) ⇒ RecordExploder
Returns a new instance of RecordExploder.
5 6 7 |
# File 'lib/fluent/plugin/record_exploder.rb', line 5 def initialize(values_retriever) @values_retriever = values_retriever end |
Instance Method Details
#explode_record(keys, record) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fluent/plugin/record_exploder.rb', line 9 def explode_record(keys, record) values = @values_retriever.retrieve_values(keys, record) key_to_explode = keys.last upper_keys = keys.reverse.drop(1).reverse new_records = values.map do |value| record_copy = Marshal.load(Marshal.dump(record)) upper_record = record_copy upper_keys.each do |key| upper_record = upper_record[key] end upper_record[key_to_explode] = value record_copy end return new_records end |