Class: ETL::Control::Destination
- Inherits:
-
Object
- Object
- ETL::Control::Destination
- Defined in:
- lib/etl/control/destination.rb
Overview
Base class for destinations.
Direct Known Subclasses
CsvDestination, DatabaseDestination, ExcelDestination, FileDestination, InsertUpdateDatabaseDestination, UpdateDatabaseDestination, YamlDestination
Instance Attribute Summary (collapse)
-
- (Object) append_rows
An array of rows to append to the destination.
-
- (Object) buffer_size
Accessor to the buffer size.
-
- (Object) condition
A condition for writing.
-
- (Object) configuration
readonly
Read-only accessor for the configuration Hash.
-
- (Object) control
readonly
Read-only accessor for the ETL::Control::Control instance.
-
- (Object) mapping
readonly
Read-only accessor for the destination mapping Hash.
-
- (Object) unique
Unique flag.
Class Method Summary (collapse)
-
+ (Object) class_for_name(name)
Get the destination class for the specified name.
Instance Method Summary (collapse)
-
- (Object) close
Abstract method.
-
- (Object) current_row
Get the current row number.
- - (Object) errors
-
- (Object) flush
Abstract method.
-
- (Destination) initialize(control, configuration, mapping)
constructor
Initialize the destination.
-
- (Object) write(row)
Write the given row.
Constructor Details
- (Destination) initialize(control, configuration, mapping)
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
- (Object) append_rows
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 |
- (Object) buffer_size
Accessor to the buffer size
15 16 17 |
# File 'lib/etl/control/destination.rb', line 15 def buffer_size @buffer_size end |
- (Object) condition
A condition for writing
21 22 23 |
# File 'lib/etl/control/destination.rb', line 21 def condition @condition end |
- (Object) configuration (readonly)
Read-only accessor for the configuration Hash
9 10 11 |
# File 'lib/etl/control/destination.rb', line 9 def configuration @configuration end |
- (Object) control (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 |
- (Object) mapping (readonly)
Read-only accessor for the destination mapping Hash
12 13 14 |
# File 'lib/etl/control/destination.rb', line 12 def mapping @mapping end |
- (Object) unique
Unique flag.
18 19 20 |
# File 'lib/etl/control/destination.rb', line 18 def unique @unique end |
Class Method Details
+ (Object) class_for_name(name)
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
- (Object) close
Abstract method
76 77 78 |
# File 'lib/etl/control/destination.rb', line 76 def close raise NotImplementedError, "close method must be implemented by subclasses" end |
- (Object) current_row
Get the current row number
58 59 60 |
# File 'lib/etl/control/destination.rb', line 58 def current_row @current_row ||= 1 end |
- (Object) errors
80 81 82 |
# File 'lib/etl/control/destination.rb', line 80 def errors @errors ||= [] end |
- (Object) flush
Abstract method
71 72 73 |
# File 'lib/etl/control/destination.rb', line 71 def flush raise NotImplementedError, "flush method must be implemented by subclasses" end |
- (Object) write(row)
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 |