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



255
256
257
# File 'lib/etl/control/control.rb', line 255

def initialize(file)
  @file = file
end

Instance Attribute Details

#error_thresholdObject

Get the error threshold. Defaults to 100.



219
220
221
# File 'lib/etl/control/control.rb', line 219

def error_threshold
  @error_threshold
end

#fileObject (readonly)

The File object



216
217
218
# File 'lib/etl/control/control.rb', line 216

def file
  @file
end

Class Method Details

.parse(control_file) ⇒ Object

Parse a control file and return a Control instance



223
224
225
226
227
228
229
230
231
# File 'lib/etl/control/control.rb', line 223

def parse(control_file)
  control_file = control_file.path if control_file.instance_of?(File)
  # logger.debug "Parsing control file #{control_file.path}"
  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

.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



240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/etl/control/control.rb', line 240

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_read_processorsObject

transforms ||= []

end


279
280
281
# File 'lib/etl/control/control.rb', line 279

def after_read_processors
  @after_read_processors ||= []
end

#before_write_processorsObject

Get all of the “before write” processors



284
285
286
# File 'lib/etl/control/control.rb', line 284

def before_write_processors
  @before_write_processors ||= []
end

#dependenciesObject

Get a list of dependencies



260
261
262
# File 'lib/etl/control/control.rb', line 260

def dependencies
  @dependencies ||= []
end

#destination_typesObject



322
323
324
# File 'lib/etl/control/control.rb', line 322

def destination_types
  [:file, :database]
end

#destinationsObject

Get the defined destinations



270
271
272
# File 'lib/etl/control/control.rb', line 270

def destinations
  @destinations ||= []
end

#post_processorsObject

Get an Array of post processors



294
295
296
# File 'lib/etl/control/control.rb', line 294

def post_processors
  @post_processors ||= []
end

#pre_processorsObject

Get an Array of preprocessors



289
290
291
# File 'lib/etl/control/control.rb', line 289

def pre_processors
  @pre_processors ||= []
end

#source_typesObject



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

def source_types
  [:file, :database]
end

#sourcesObject

Get the defined source



265
266
267
# File 'lib/etl/control/control.rb', line 265

def sources
  @sources ||= []
end

#transformsObject

Get an Array of all transforms for this control



299
300
301
# File 'lib/etl/control/control.rb', line 299

def transforms
  @transforms ||= []
end

#validateObject

Validate the control file



309
310
311
312
313
314
315
316
# File 'lib/etl/control/control.rb', line 309

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