Class: Chronicle::ETL::Transformer
- Inherits:
-
Object
- Object
- Chronicle::ETL::Transformer
- Extended by:
- Registry::SelfRegistering
- Includes:
- Configurable
- Defined in:
- lib/chronicle/etl/transformers/transformer.rb
Overview
Abstract class representing an Transformer for an ETL job
Direct Known Subclasses
BufferTransformer, ChronicleTransformer, ChronobaseTransformer, FieldsLimitTransformer, FilterFieldsTransformer, FilterTransformer, FormatTransformer, MergeMetaTransformer, MultiplyTransformer, NullTransformer, SamplerTransformer, SortTransformer
Instance Attribute Summary collapse
-
#stashed_records ⇒ Object
readonly
Returns the value of attribute stashed_records.
Attributes included from Registry::SelfRegistering
Instance Method Summary collapse
-
#call(record, &block) ⇒ Object
Called once for each extracted record.
- #call_finish(&block) ⇒ Object
-
#finish ⇒ Object
Called once after runner has processed all records.
-
#initialize(options = {}) ⇒ Transformer
constructor
Construct a new instance of this transformer.
- #transform(_record) ⇒ Object
Methods included from Registry::SelfRegistering
Methods included from Configurable
Constructor Details
#initialize(options = {}) ⇒ Transformer
Construct a new instance of this transformer. Options are passed in from a Runner == Parameters: options:: Options for configuring this Transformer
16 17 18 |
# File 'lib/chronicle/etl/transformers/transformer.rb', line 16 def initialize( = {}) () end |
Instance Attribute Details
#stashed_records ⇒ Object (readonly)
Returns the value of attribute stashed_records.
10 11 12 |
# File 'lib/chronicle/etl/transformers/transformer.rb', line 10 def stashed_records @stashed_records end |
Instance Method Details
#call(record, &block) ⇒ Object
Called once for each extracted record. Can return 0 or more transformed records.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chronicle/etl/transformers/transformer.rb', line 21 def call(record, &block) raise ArgumentError, 'Input must be a Chronicle::ETL::Record' unless record.is_a?(Record) yielded = false transformed_data = transform(record) do |data| new_record = update_data(record, data) block.call(new_record) yielded = true end return if yielded # Handle transformers that don't yield anything and return # transformed data directly. Skip nil values. [transformed_data].flatten.compact.each do |data| new_record = update_data(record, data) block.call(new_record) end end |
#call_finish(&block) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/chronicle/etl/transformers/transformer.rb', line 43 def call_finish(&block) remaining_records = finish return if remaining_records.nil? remaining_records.each do |record| block.call(record) end end |
#finish ⇒ Object
Called once after runner has processed all records
57 |
# File 'lib/chronicle/etl/transformers/transformer.rb', line 57 def finish; end |
#transform(_record) ⇒ Object
52 53 54 |
# File 'lib/chronicle/etl/transformers/transformer.rb', line 52 def transform(_record) raise NotImplementedError, 'You must implement the transform method' end |