Class: ETL::Processor::HierarchyExploderProcessor

Inherits:
RowProcessor show all
Defined in:
lib/etl/processor/hierarchy_exploder_processor.rb

Overview

Row-level processor that will convert a single row into multiple rows designed to be inserted into a hierarchy bridge table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RowProcessor

#ensure_columns_available_in_row!

Constructor Details

#initialize(control, configuration = {}) ⇒ HierarchyExploderProcessor

Initialize the processor

Configuration options:

  • :connection: The ActiveRecord adapter connection

  • :id_field: The name of the id field (defaults to ‘id’)

  • :parent_id_field: The name of the parent id field (defaults to ‘parent_id’)

TODO: Allow resolver to be implemented in a customizable fashion, i.e. don’t rely on AR as the only resolution method.



18
19
20
21
22
# File 'lib/etl/processor/hierarchy_exploder_processor.rb', line 18

def initialize(control, configuration={})
  @id_field = configuration[:id_field] || 'id'
  @parent_id_field = configuration[:parent_id_field] || 'parent_id'
  super
end

Instance Attribute Details

#id_fieldObject

Returns the value of attribute id_field.



6
7
8
# File 'lib/etl/processor/hierarchy_exploder_processor.rb', line 6

def id_field
  @id_field
end

#parent_id_fieldObject

Returns the value of attribute parent_id_field.



7
8
9
# File 'lib/etl/processor/hierarchy_exploder_processor.rb', line 7

def parent_id_field
  @parent_id_field
end

Instance Method Details

#process(row) ⇒ Object

Process the row expanding it into hierarchy values



25
26
27
28
29
30
31
32
# File 'lib/etl/processor/hierarchy_exploder_processor.rb', line 25

def process(row)
  rows = []
  target = configuration[:target]
  table = configuration[:table]
  conn = ETL::Engine.connection(target)
  build_rows([row[:id]], row[:id], row[:id], row[:parent_id].nil?, 0, rows, table, conn)
  rows
end