Class: ETL::Control::Context
- Inherits:
-
Object
- Object
- ETL::Control::Context
- Includes:
- Test::Unit::Assertions
- Defined in:
- lib/etl/control/control.rb
Overview
The Context is passed to eval.
Instance Attribute Summary (collapse)
-
- (Object) control
readonly
Returns the value of attribute control.
Class Method Summary (collapse)
-
+ (Object) create(control)
Create a Context instance.
Instance Method Summary (collapse)
-
- (Object) after_post_process_screen(type, &block)
Define an after post-proces screen block.
-
- (Object) after_post_process_screens
Get the after post-process screen blocks.
-
- (Object) after_read(name = 'block', configuration = {}, &block)
Define an "after read" processor.
-
- (Object) after_read_processors
Get the defined "after read" processors.
-
- (Object) before_write(name = 'block', configuration = {}, &block)
Define a "before write" processor.
-
- (Object) before_write_processors
Get the defined "before write" processors.
-
- (Object) copy(source, destination)
Copy the source field to the destination field.
-
- (Object) dependencies
Get the defined dependencies.
-
- (Object) depends_on(*args)
Define a list of control files that this file depends on.
-
- (Object) destination(name, configuration = {}, mapping = {})
Define a destination.
-
- (Object) destinations
Get the defined destinations.
-
- (Object) file
Get the control file.
-
- (Object) get_binding
Get the binding object.
-
- (Context) initialize(control)
constructor
Initialize the context.
-
- (Object) post_process(name = 'block', configuration = {}, &block)
Define a post-processor.
-
- (Object) post_processors
Get the defined post-processors.
-
- (Object) pre_process(name = 'block', configuration = {}, &block)
Define a pre-processor.
-
- (Object) pre_processors
Get the defined pre-processors.
-
- (Object) rename(source, destination)
Rename the source field to the destination field.
-
- (Object) screen(type, &block)
Define a before post-process screen block.
-
- (Object) screens
Get the before post-process screen blocks.
-
- (Object) set_error_threshold(error_threshold)
Set the allowed error threshold.
-
- (Object) source(name, configuration = {}, definition = {})
Define a source.
-
- (Object) sources
Get the defined source.
-
- (Object) transform(name, transformer = nil, configuration = {}, &block)
Define a transform.
-
- (Object) transforms
Get the defined transforms.
Constructor Details
- (Context) initialize(control)
Initialize the context
17 18 19 |
# File 'lib/etl/control/control.rb', line 17 def initialize(control) @control = control end |
Instance Attribute Details
- (Object) control (readonly)
Returns the value of attribute control
7 8 9 |
# File 'lib/etl/control/control.rb', line 7 def control @control end |
Class Method Details
+ (Object) create(control)
Create a Context instance
11 12 13 |
# File 'lib/etl/control/control.rb', line 11 def create(control) Context.new(control).get_binding end |
Instance Method Details
- (Object) after_post_process_screen(type, &block)
Define an after post-proces screen block. The type argument must be one of :fatal, :error or :warn
163 164 165 |
# File 'lib/etl/control/control.rb', line 163 def after_post_process_screen(type, &block) after_post_process_screens[type] << block end |
- (Object) after_post_process_screens
Get the after post-process screen blocks
168 169 170 |
# File 'lib/etl/control/control.rb', line 168 def after_post_process_screens control.after_post_process_screens end |
- (Object) after_read(name = 'block', configuration = {}, &block)
Define an "after read" processor. This must be a row-level processor.
209 210 211 |
# File 'lib/etl/control/control.rb', line 209 def after_read(name='block', configuration={}, &block) define_processor(name, after_read_processors, configuration, block) end |
- (Object) after_read_processors
Get the defined "after read" processors
214 215 216 |
# File 'lib/etl/control/control.rb', line 214 def after_read_processors control.after_read_processors end |
- (Object) before_write(name = 'block', configuration = {}, &block)
Define a "before write" processor. This must be a row-level processor.
219 220 221 |
# File 'lib/etl/control/control.rb', line 219 def before_write(name='block', configuration={}, &block) define_processor(name, before_write_processors, configuration, block) end |
- (Object) before_write_processors
Get the defined "before write" processors
224 225 226 |
# File 'lib/etl/control/control.rb', line 224 def before_write_processors control.before_write_processors end |
- (Object) copy(source, destination)
Copy the source field to the destination field
178 179 180 |
# File 'lib/etl/control/control.rb', line 178 def copy(source, destination) after_read :copy_field, :source => source, :dest => destination end |
- (Object) dependencies
Get the defined dependencies
41 42 43 |
# File 'lib/etl/control/control.rb', line 41 def dependencies control.dependencies end |
- (Object) depends_on(*args)
Define a list of control files that this file depends on. Those control files will be executed prior to this control file. The list may contain symbols that will be converted to file names by calling to_s + '.ctl', or they may be strings in which case they will be used as is
36 37 38 |
# File 'lib/etl/control/control.rb', line 36 def depends_on(*args) (dependencies << args).flatten! end |
- (Object) destination(name, configuration = {}, mapping = {})
Define a destination
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/etl/control/control.rb', line 80 def destination(name, configuration={}, mapping={}) if configuration[:type] case configuration[:type] when Class dest_class = configuration[:type] destinations << dest_class.new(self, configuration, mapping) when String, Symbol dest_class = ETL::Control::Destination.class_for_name(configuration[:type]) destinations << dest_class.new(self, configuration, mapping) else if configuration[:type].is_a?(ETL::Control::Destination) destinations << configuration[:type] else raise ControlError, "Type must be a Class, String, Symbol or object extending ETL::Control::Destination" end end else destination_types.each do |dest_type| if configuration[dest_type] dest_class = ETL::Control::Destination.class_for_name(dest_type) destinations << dest_class.new(self, configuration, mapping) break end end raise ControlError, "A destination was specified but no matching destination type was found" if destinations.empty? end end |
- (Object) destinations
Get the defined destinations
109 110 111 |
# File 'lib/etl/control/control.rb', line 109 def destinations control.destinations end |
- (Object) file
Get the control file
22 23 24 |
# File 'lib/etl/control/control.rb', line 22 def file control.file end |
- (Object) get_binding
Get the binding object
249 250 251 |
# File 'lib/etl/control/control.rb', line 249 def get_binding binding end |
- (Object) post_process(name = 'block', configuration = {}, &block)
Define a post-processor
239 240 241 |
# File 'lib/etl/control/control.rb', line 239 def post_process(name='block', configuration={}, &block) define_processor(name, post_processors, configuration, block) end |
- (Object) post_processors
Get the defined post-processors
244 245 246 |
# File 'lib/etl/control/control.rb', line 244 def post_processors control.post_processors end |
- (Object) pre_process(name = 'block', configuration = {}, &block)
Define a pre-processor
229 230 231 |
# File 'lib/etl/control/control.rb', line 229 def pre_process(name='block', configuration={}, &block) define_processor(name, pre_processors, configuration, block) end |
- (Object) pre_processors
Get the defined pre-processors
234 235 236 |
# File 'lib/etl/control/control.rb', line 234 def pre_processors control.pre_processors end |
- (Object) rename(source, destination)
Rename the source field to the destination field
173 174 175 |
# File 'lib/etl/control/control.rb', line 173 def rename(source, destination) after_read :rename, :source => source, :dest => destination end |
- (Object) screen(type, &block)
Define a before post-process screen block. The type argument must be one of :fatal, :error or :warn
152 153 154 |
# File 'lib/etl/control/control.rb', line 152 def screen(type, &block) screens[type] << block end |
- (Object) screens
Get the before post-process screen blocks
157 158 159 |
# File 'lib/etl/control/control.rb', line 157 def screens control.screens end |
- (Object) set_error_threshold(error_threshold)
Set the allowed error threshold
27 28 29 |
# File 'lib/etl/control/control.rb', line 27 def set_error_threshold(error_threshold) control.error_threshold = error_threshold end |
- (Object) source(name, configuration = {}, definition = {})
Define a source.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/etl/control/control.rb', line 46 def source(name, configuration={}, definition={}) if configuration[:type] case configuration[:type] when Class source_class = configuration[:type] sources << source_class.new(self, configuration, definition) when String, Symbol source_class = ETL::Control::Source.class_for_name(configuration[:type]) sources << source_class.new(self, configuration, definition) else if configuration[:type].is_a?(ETL::Control::Source) sources << configuration[:type] else raise ControlError, "Type must be a Class, String, Symbol or object extending ETL::Control::Source" end end else source_types.each do |source_type| if configuration[source_type] source_class = ETL::Control::Source.class_for_name(source_type) sources << source_class.new(self, configuration, definition) break end end raise ControlError, "A source was specified but no matching type was found" if sources.empty? end end |
- (Object) sources
Get the defined source
75 76 77 |
# File 'lib/etl/control/control.rb', line 75 def sources control.sources end |
- (Object) transform(name, transformer = nil, configuration = {}, &block)
Define a transform
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/etl/control/control.rb', line 114 def transform(name, transformer=nil, configuration={}, &block) if transformer case transformer when String, Symbol class_name = "#{transformer.to_s.camelize}Transform" begin transform_class = ETL::Transform.const_get(class_name) transforms << transform_class.new(self, name, configuration) rescue NameError => e raise ControlError, "Unable to find transformer #{class_name}: #{e}" end when Class transforms << transformer.new(self, transformer.name, configuration) else #transformer.class.inspect if transformer.is_a?(ETL::Transform::Transform) Engine.logger.debug "Adding transformer #{transformer.inspect} for field #{name}" t = transformer.dup t.name = name transforms << t else raise ControlError, "Transformer must be a String, Symbol, Class or Transform instance" end end elsif block_given? transforms << ETL::Transform::BlockTransform.new(self, name, :block => block) else raise ControlError, "Either a transformer or a block must be specified" end end |
- (Object) transforms
Get the defined transforms
146 147 148 |
# File 'lib/etl/control/control.rb', line 146 def transforms control.transforms end |