Class: ETL::Control::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/etl/control/control.rb

Overview

Object representation of a control file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_thresholdObject

Get the error threshold. Defaults to 100.



272
273
274
# File 'lib/etl/control/control.rb', line 272

def error_threshold
  @error_threshold
end

#fileObject (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_screensObject

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_processorsObject

transforms ||= []

end


338
339
340
# File 'lib/etl/control/control.rb', line 338

def after_read_processors
  @after_read_processors ||= []
end

#before_write_processorsObject

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

#dependenciesObject

Get a list of dependencies



319
320
321
# File 'lib/etl/control/control.rb', line 319

def dependencies
  @dependencies ||= []
end

#destination_typesObject



399
400
401
# File 'lib/etl/control/control.rb', line 399

def destination_types
  [:file, :database]
end

#destinationsObject

Get the defined destinations



329
330
331
# File 'lib/etl/control/control.rb', line 329

def destinations
  @destinations ||= []
end

#post_processorsObject

Get an Array of post processors



353
354
355
# File 'lib/etl/control/control.rb', line 353

def post_processors
  @post_processors ||= []
end

#pre_processorsObject

Get an Array of preprocessors



348
349
350
# File 'lib/etl/control/control.rb', line 348

def pre_processors
  @pre_processors ||= []
end

#screensObject

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_typesObject



395
396
397
# File 'lib/etl/control/control.rb', line 395

def source_types
  [:file, :database]
end

#sourcesObject

Get the defined source



324
325
326
# File 'lib/etl/control/control.rb', line 324

def sources
  @sources ||= []
end

#transformsObject

Get an Array of all transforms for this control



358
359
360
# File 'lib/etl/control/control.rb', line 358

def transforms
  @transforms ||= []
end

#validateObject

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