Class: ETL::Control::Control
- Inherits:
-
Object
- Object
- ETL::Control::Control
- Defined in:
- lib/etl/control/control.rb
Overview
Object representation of a control file
Instance Attribute Summary collapse
-
#error_threshold ⇒ Object
Get the error threshold.
-
#file ⇒ Object
readonly
The File object.
Class Method Summary collapse
-
.parse(control_file) ⇒ Object
Parse a control file and return a Control instance.
- .parse_text(text) ⇒ Object
-
.resolve(control) ⇒ Object
Resolve the given object to an ETL::Control::Control instance.
Instance Method Summary collapse
-
#after_post_process_screens ⇒ Object
A hash of the screens executed after post-process.
-
#after_read_processors ⇒ Object
transforms ||= [] end.
-
#before_write_processors ⇒ Object
Get all of the “before write” processors.
-
#dependencies ⇒ Object
Get a list of dependencies.
- #destination_types ⇒ Object
-
#destinations ⇒ Object
Get the defined destinations.
-
#initialize(file) ⇒ Control
constructor
Initialize the instance with the given File object.
-
#post_processors ⇒ Object
Get an Array of post processors.
-
#pre_processors ⇒ Object
Get an Array of preprocessors.
-
#screens ⇒ Object
A hash of the screens executed before post-process.
- #source_types ⇒ Object
-
#sources ⇒ Object
Get the defined source.
-
#transforms ⇒ Object
Get an Array of all transforms for this control.
-
#validate ⇒ Object
Validate the control file.
Constructor Details
#initialize(file) ⇒ Control
Initialize the instance with the given File object
314 315 316 |
# File 'lib/etl/control/control.rb', line 314 def initialize(file) @file = file end |
Instance Attribute Details
#error_threshold ⇒ Object
Get the error threshold. Defaults to 100.
272 273 274 |
# File 'lib/etl/control/control.rb', line 272 def error_threshold @error_threshold end |
#file ⇒ Object (readonly)
The File object
269 270 271 |
# File 'lib/etl/control/control.rb', line 269 def file @file end |
Class Method Details
.parse(control_file) ⇒ Object
Parse a control file and return a Control instance
276 277 278 279 280 281 282 283 |
# File 'lib/etl/control/control.rb', line 276 def parse(control_file) control_file = control_file.path if control_file.instance_of?(File) control = ETL::Control::Control.new(control_file) # TODO: better handling of parser errors. Return the line in the control file where the error occurs. eval(IO.readlines(control_file).join("\n"), Context.create(control), control_file) control.validate control end |
.parse_text(text) ⇒ Object
285 286 287 288 289 290 |
# File 'lib/etl/control/control.rb', line 285 def parse_text(text) control = ETL::Control::Control.new(nil) eval(text, Context.create(control), 'inline') control.validate control end |
.resolve(control) ⇒ Object
Resolve the given object to an ETL::Control::Control instance. Acceptable arguments are:
-
The path to a control file as a String
-
A File object referencing the control file
-
The ETL::Control::Control object (which will just be returned)
Raises a ControlError if any other type is given
299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/etl/control/control.rb', line 299 def resolve(control) case control when String ETL::Control::Control.parse(File.new(control)) when File ETL::Control::Control.parse(control) when ETL::Control::Control control else raise ControlError, "Control must be a String, File or Control object" end end |
Instance Method Details
#after_post_process_screens ⇒ Object
A hash of the screens executed after post-process
372 373 374 375 376 377 378 |
# File 'lib/etl/control/control.rb', line 372 def after_post_process_screens @after_post_process_screens ||= { :fatal => [], :error => [], :warn => [] } end |
#after_read_processors ⇒ Object
transforms ||= []
end
338 339 340 |
# File 'lib/etl/control/control.rb', line 338 def after_read_processors @after_read_processors ||= [] end |
#before_write_processors ⇒ Object
Get all of the “before write” processors
343 344 345 |
# File 'lib/etl/control/control.rb', line 343 def before_write_processors @before_write_processors ||= [] end |
#dependencies ⇒ Object
Get a list of dependencies
319 320 321 |
# File 'lib/etl/control/control.rb', line 319 def dependencies @dependencies ||= [] end |
#destination_types ⇒ Object
399 400 401 |
# File 'lib/etl/control/control.rb', line 399 def destination_types [:file, :database] end |
#destinations ⇒ Object
Get the defined destinations
329 330 331 |
# File 'lib/etl/control/control.rb', line 329 def destinations @destinations ||= [] end |
#post_processors ⇒ Object
Get an Array of post processors
353 354 355 |
# File 'lib/etl/control/control.rb', line 353 def post_processors @post_processors ||= [] end |
#pre_processors ⇒ Object
Get an Array of preprocessors
348 349 350 |
# File 'lib/etl/control/control.rb', line 348 def pre_processors @pre_processors ||= [] end |
#screens ⇒ Object
A hash of the screens executed before post-process
363 364 365 366 367 368 369 |
# File 'lib/etl/control/control.rb', line 363 def screens @screens ||= { :fatal => [], :error => [], :warn => [] } end |
#source_types ⇒ Object
395 396 397 |
# File 'lib/etl/control/control.rb', line 395 def source_types [:file, :database] end |
#sources ⇒ Object
Get the defined source
324 325 326 |
# File 'lib/etl/control/control.rb', line 324 def sources @sources ||= [] end |
#transforms ⇒ Object
Get an Array of all transforms for this control
358 359 360 |
# File 'lib/etl/control/control.rb', line 358 def transforms @transforms ||= [] end |
#validate ⇒ Object
Validate the control file
386 387 388 389 390 391 392 393 |
# File 'lib/etl/control/control.rb', line 386 def validate #unless sources.length > 0 # raise ControlError, "Configuration must include one of the following for the source: #{source_types.join(',')}" #end #unless destinations.length > 0 # raise ControlError, "Configuration must include one of the following for the destination: #{destination_types.join(',')}" #end end |