Class: ETL::Control::Destination

Inherits:
Object
  • Object
show all
Defined in:
lib/etl/control/destination.rb

Overview

Base class for destinations.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control, configuration, mapping) ⇒ Destination

Initialize the destination

Arguments:

  • control: The ETL::Control::Control instance

  • configuration: The configuration Hash

  • mapping: The mapping Hash

Options:

  • :buffer_size: The output buffer size (default 1000 records)

  • :condition: A conditional proc that must return true for the row to be written

  • :append_rows: An array of rows to append



48
49
50
51
52
53
54
55
# File 'lib/etl/control/destination.rb', line 48

def initialize(control, configuration, mapping)
  @control = control
  @configuration = configuration
  @mapping = mapping
  @buffer_size = configuration[:buffer_size] ||= 100
  @condition = configuration[:condition]
  @append_rows = configuration[:append_rows]
end

Instance Attribute Details

#append_rowsObject

An array of rows to append to the destination



24
25
26
# File 'lib/etl/control/destination.rb', line 24

def append_rows
  @append_rows
end

#buffer_sizeObject

Accessor to the buffer size



15
16
17
# File 'lib/etl/control/destination.rb', line 15

def buffer_size
  @buffer_size
end

#conditionObject

A condition for writing



21
22
23
# File 'lib/etl/control/destination.rb', line 21

def condition
  @condition
end

#configurationObject (readonly)

Read-only accessor for the configuration Hash



9
10
11
# File 'lib/etl/control/destination.rb', line 9

def configuration
  @configuration
end

#controlObject (readonly)

Read-only accessor for the ETL::Control::Control instance



6
7
8
# File 'lib/etl/control/destination.rb', line 6

def control
  @control
end

#mappingObject (readonly)

Read-only accessor for the destination mapping Hash



12
13
14
# File 'lib/etl/control/destination.rb', line 12

def mapping
  @mapping
end

#uniqueObject

Unique flag.



18
19
20
# File 'lib/etl/control/destination.rb', line 18

def unique
  @unique
end

Class Method Details

.class_for_name(name) ⇒ Object

Get the destination class for the specified name.

For example if name is :database or ‘database’ then the DatabaseDestination class is returned



31
32
33
# File 'lib/etl/control/destination.rb', line 31

def class_for_name(name)
  ETL::Control.const_get("#{name.to_s.camelize}Destination")
end

Instance Method Details

#closeObject

Abstract method

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/etl/control/destination.rb', line 76

def close
  raise NotImplementedError, "close method must be implemented by subclasses"
end

#current_rowObject

Get the current row number



58
59
60
# File 'lib/etl/control/destination.rb', line 58

def current_row
  @current_row ||= 1
end

#errorsObject



80
81
82
# File 'lib/etl/control/destination.rb', line 80

def errors
  @errors ||= []
end

#flushObject

Abstract method

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/etl/control/destination.rb', line 71

def flush
  raise NotImplementedError, "flush method must be implemented by subclasses"
end

#write(row) ⇒ Object

Write the given row



63
64
65
66
67
68
# File 'lib/etl/control/destination.rb', line 63

def write(row)
  if @condition.nil? || @condition.call(row)
    process_change(row)
  end
  flush if buffer.length >= buffer_size
end