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



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

def initialize(file)
  @file = file
end

Instance Attribute Details

#error_thresholdObject

Get the error threshold. Defaults to 100.



277
278
279
# File 'lib/etl/control/control.rb', line 277

def error_threshold
  @error_threshold
end

#fileObject (readonly)

The File object



274
275
276
# File 'lib/etl/control/control.rb', line 274

def file
  @file
end

Class Method Details

.parse(control_file) ⇒ Object

Parse a control file and return a Control instance



281
282
283
284
285
286
287
288
# File 'lib/etl/control/control.rb', line 281

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



290
291
292
293
294
295
# File 'lib/etl/control/control.rb', line 290

def parse_text(text)
  control = ETL::Control::Control.new('no-file')
  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



304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/etl/control/control.rb', line 304

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



377
378
379
380
381
382
383
# File 'lib/etl/control/control.rb', line 377

def after_post_process_screens
  @after_post_process_screens ||= {
    :fatal => [],
    :error => [],
    :warn => []
  }
end

#after_read_processorsObject

transforms ||= []

end


343
344
345
# File 'lib/etl/control/control.rb', line 343

def after_read_processors
  @after_read_processors ||= []
end

#before_write_processorsObject

Get all of the “before write” processors



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

def before_write_processors
  @before_write_processors ||= []
end

#dependenciesObject

Get a list of dependencies



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

def dependencies
  @dependencies ||= []
end

#destination_typesObject



409
410
411
# File 'lib/etl/control/control.rb', line 409

def destination_types
  [:file, :database]
end

#destinationsObject

Get the defined destinations



334
335
336
# File 'lib/etl/control/control.rb', line 334

def destinations
  @destinations ||= []
end

#error_handlersObject

A array of Procs to be invoked for errors notifications



386
387
388
# File 'lib/etl/control/control.rb', line 386

def error_handlers
  @error_handlers ||= []
end

#post_processorsObject

Get an Array of post processors



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

def post_processors
  @post_processors ||= []
end

#pre_processorsObject

Get an Array of preprocessors



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

def pre_processors
  @pre_processors ||= []
end

#screensObject

A hash of the screens executed before post-process



368
369
370
371
372
373
374
# File 'lib/etl/control/control.rb', line 368

def screens
  @screens ||= {
    :fatal => [],
    :error => [],
    :warn => []
  }
end

#source_typesObject



405
406
407
# File 'lib/etl/control/control.rb', line 405

def source_types
  [:file, :database]
end

#sourcesObject

Get the defined source



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

def sources
  @sources ||= []
end

#transformsObject

Get an Array of all transforms for this control



363
364
365
# File 'lib/etl/control/control.rb', line 363

def transforms
  @transforms ||= []
end

#validateObject

Validate the control file



396
397
398
399
400
401
402
403
# File 'lib/etl/control/control.rb', line 396

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