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
-
#control ⇒ Object
readonly
Returns the value of attribute control.
Class Method Summary collapse
-
.create(control) ⇒ Object
Create a Context instance.
Instance Method Summary collapse
-
#after_post_process_screen(type, &block) ⇒ Object
Define an after post-proces screen block.
-
#after_post_process_screens ⇒ Object
Get the after post-process screen blocks.
-
#after_read(name = 'block', configuration = {}, &block) ⇒ Object
Define an “after read” processor.
-
#after_read_processors ⇒ Object
Get the defined “after read” processors.
-
#before_write(name = 'block', configuration = {}, &block) ⇒ Object
Define a “before write” processor.
-
#before_write_processors ⇒ Object
Get the defined “before write” processors.
-
#copy(source, destination) ⇒ Object
Copy the source field to the destination field.
-
#dependencies ⇒ Object
Get the defined dependencies.
-
#depends_on(*args) ⇒ Object
Define a list of control files that this file depends on.
-
#destination(name, configuration = {}, mapping = {}) ⇒ Object
Define a destination.
-
#destinations ⇒ Object
Get the defined destinations.
-
#file ⇒ Object
Get the control file.
-
#get_binding ⇒ Object
Get the binding object.
-
#initialize(control) ⇒ Context
constructor
Initialize the context.
-
#post_process(name = 'block', configuration = {}, &block) ⇒ Object
Define a post-processor.
-
#post_processors ⇒ Object
Get the defined post-processors.
-
#pre_process(name = 'block', configuration = {}, &block) ⇒ Object
Define a pre-processor.
-
#pre_processors ⇒ Object
Get the defined pre-processors.
-
#rename(source, destination) ⇒ Object
Rename the source field to the destination field.
-
#screen(type, &block) ⇒ Object
Define a before post-process screen block.
-
#screens ⇒ Object
Get the before post-process screen blocks.
-
#set_error_threshold(error_threshold) ⇒ Object
Set the allowed error threshold.
-
#source(name, configuration = {}, definition = {}) ⇒ Object
Define a source.
-
#sources ⇒ Object
Get the defined source.
-
#transform(name, transformer = nil, configuration = {}, &block) ⇒ Object
Define a transform.
-
#transforms ⇒ Object
Get the defined transforms.
Constructor Details
#initialize(control) ⇒ Context
Initialize the context
17 18 19 |
# File 'lib/etl/control/control.rb', line 17 def initialize(control) @control = control end |
Instance Attribute Details
#control ⇒ Object (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
.create(control) ⇒ Object
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
#after_post_process_screen(type, &block) ⇒ Object
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 |
#after_post_process_screens ⇒ Object
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 |
#after_read(name = 'block', configuration = {}, &block) ⇒ Object
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 |
#after_read_processors ⇒ Object
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 |
#before_write(name = 'block', configuration = {}, &block) ⇒ Object
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 |
#before_write_processors ⇒ Object
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 |
#copy(source, destination) ⇒ Object
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 |
#dependencies ⇒ Object
Get the defined dependencies
41 42 43 |
# File 'lib/etl/control/control.rb', line 41 def dependencies control.dependencies end |
#depends_on(*args) ⇒ Object
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 |
#destination(name, configuration = {}, mapping = {}) ⇒ Object
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 |
#destinations ⇒ Object
Get the defined destinations
109 110 111 |
# File 'lib/etl/control/control.rb', line 109 def destinations control.destinations end |
#file ⇒ Object
Get the control file
22 23 24 |
# File 'lib/etl/control/control.rb', line 22 def file control.file end |
#get_binding ⇒ Object
Get the binding object
249 250 251 |
# File 'lib/etl/control/control.rb', line 249 def get_binding binding end |
#post_process(name = 'block', configuration = {}, &block) ⇒ Object
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 |
#post_processors ⇒ Object
Get the defined post-processors
244 245 246 |
# File 'lib/etl/control/control.rb', line 244 def post_processors control.post_processors end |
#pre_process(name = 'block', configuration = {}, &block) ⇒ Object
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 |
#pre_processors ⇒ Object
Get the defined pre-processors
234 235 236 |
# File 'lib/etl/control/control.rb', line 234 def pre_processors control.pre_processors end |
#rename(source, destination) ⇒ Object
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 |
#screen(type, &block) ⇒ Object
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 |
#screens ⇒ Object
Get the before post-process screen blocks
157 158 159 |
# File 'lib/etl/control/control.rb', line 157 def screens control.screens end |
#set_error_threshold(error_threshold) ⇒ Object
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 |
#source(name, configuration = {}, definition = {}) ⇒ Object
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 |
#sources ⇒ Object
Get the defined source
75 76 77 |
# File 'lib/etl/control/control.rb', line 75 def sources control.sources end |
#transform(name, transformer = nil, configuration = {}, &block) ⇒ Object
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 |
#transforms ⇒ Object
Get the defined transforms
146 147 148 |
# File 'lib/etl/control/control.rb', line 146 def transforms control.transforms end |