Class: ETL::Processor::SurrogateKeyProcessor

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

Overview

A row level processor that provides surrogate keys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control, configuration) ⇒ SurrogateKeyProcessor

Initialize the surrogate key generator



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/etl/processor/surrogate_key_processor.rb', line 9

def initialize(control, configuration)
  super
  if configuration[:query]
    @surrogate_key = ETL::ActiveRecord::Base.connection.select_value(configuration[:query])
  end
  #puts "initial surrogate key: #{@surrogate_key}"
  @surrogate_key = 0 if @surrogate_key.blank?
  @surrogate_key = @surrogate_key.to_i
  #puts "surrogate key: #{@surrogate_key}"
  @destination = configuration[:destination] || :id
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



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

def destination
  @destination
end

#queryObject

Returns the value of attribute query.



5
6
7
# File 'lib/etl/processor/surrogate_key_processor.rb', line 5

def query
  @query
end

Instance Method Details

#process(row) ⇒ Object

Add a surrogate key to the row



22
23
24
25
26
27
28
29
30
# File 'lib/etl/processor/surrogate_key_processor.rb', line 22

def process(row)
  if row
    #puts "processing row #{row.inspect}"
    @surrogate_key += 1
    #puts "adding surrogate key to row: #{@surrogate_key}"
    row[destination] = @surrogate_key
    row
  end
end