Class: 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
-
#append_rows ⇒ Object
An array of rows to append to the destination.
-
#buffer_size ⇒ Object
Accessor to the buffer size.
-
#condition ⇒ Object
A condition for writing.
-
#configuration ⇒ Object
readonly
Read-only accessor for the configuration Hash.
-
#control ⇒ Object
readonly
Read-only accessor for the ETL::Control::Control instance.
-
#mapping ⇒ Object
readonly
Read-only accessor for the destination mapping Hash.
-
#unique ⇒ Object
Unique flag.
Class Method Summary collapse
-
.class_for_name(name) ⇒ Object
Get the destination class for the specified name.
Instance Method Summary collapse
-
#close ⇒ Object
Abstract method.
-
#current_row ⇒ Object
Get the current row number.
- #errors ⇒ Object
-
#flush ⇒ Object
Abstract method.
-
#initialize(control, configuration, mapping) ⇒ Destination
constructor
Initialize the destination.
-
#write(row) ⇒ Object
Write the given row.
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_rows ⇒ Object
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_size ⇒ Object
Accessor to the buffer size
15 16 17 |
# File 'lib/etl/control/destination.rb', line 15 def buffer_size @buffer_size end |
#condition ⇒ Object
A condition for writing
21 22 23 |
# File 'lib/etl/control/destination.rb', line 21 def condition @condition end |
#configuration ⇒ Object (readonly)
Read-only accessor for the configuration Hash
9 10 11 |
# File 'lib/etl/control/destination.rb', line 9 def configuration @configuration end |
#control ⇒ Object (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 |
#mapping ⇒ Object (readonly)
Read-only accessor for the destination mapping Hash
12 13 14 |
# File 'lib/etl/control/destination.rb', line 12 def mapping @mapping end |
#unique ⇒ Object
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
#close ⇒ Object
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 |
#current_row ⇒ Object
Get the current row number
58 59 60 |
# File 'lib/etl/control/destination.rb', line 58 def current_row @current_row ||= 1 end |
#errors ⇒ Object
80 81 82 |
# File 'lib/etl/control/destination.rb', line 80 def errors @errors ||= [] end |
#flush ⇒ Object
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 |
#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 |