Class: ETL::Processor::EnsureFieldsPresenceProcessor

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

Overview

Ensure that each specified field is available

Instance Method Summary collapse

Methods inherited from RowProcessor

#ensure_columns_available_in_row!

Constructor Details

#initialize(control, configuration) ⇒ EnsureFieldsPresenceProcessor

Initialize the processor.

Configuration options:

  • :fields: An array of keys whose presence should be verified in each row

Raises:



10
11
12
13
14
# File 'lib/etl/processor/ensure_fields_presence_processor.rb', line 10

def initialize(control, configuration)
  super
  @fields = configuration[:fields]
  raise ControlError, ":fields must be specified" unless @fields
end

Instance Method Details

#process(row) ⇒ Object

Raises:



16
17
18
19
20
21
# File 'lib/etl/processor/ensure_fields_presence_processor.rb', line 16

def process(row)
  missing_fields = configuration[:fields].map(&:to_s) - row.keys.map(&:to_s)
  raise(ETL::ControlError, 
    "Row missing required field(s) #{missing_fields.join(',')} in row. Available fields are : #{row.keys.join(',')}") unless missing_fields.empty?
  row
end