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_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
- #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
296 297 298 |
# File 'lib/etl/control/control.rb', line 296 def initialize(file) @file = file end |
Instance Attribute Details
#error_threshold ⇒ Object
Get the error threshold. Defaults to 100.
254 255 256 |
# File 'lib/etl/control/control.rb', line 254 def error_threshold @error_threshold end |
#file ⇒ Object (readonly)
The File object
251 252 253 |
# File 'lib/etl/control/control.rb', line 251 def file @file end |
Class Method Details
.parse(control_file) ⇒ Object
Parse a control file and return a Control instance
258 259 260 261 262 263 264 265 |
# File 'lib/etl/control/control.rb', line 258 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
267 268 269 270 271 272 |
# File 'lib/etl/control/control.rb', line 267 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
281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/etl/control/control.rb', line 281 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_processors ⇒ Object
transforms ||= []
end
320 321 322 |
# File 'lib/etl/control/control.rb', line 320 def after_read_processors @after_read_processors ||= [] end |
#before_write_processors ⇒ Object
Get all of the “before write” processors
325 326 327 |
# File 'lib/etl/control/control.rb', line 325 def before_write_processors @before_write_processors ||= [] end |
#dependencies ⇒ Object
Get a list of dependencies
301 302 303 |
# File 'lib/etl/control/control.rb', line 301 def dependencies @dependencies ||= [] end |
#destination_types ⇒ Object
371 372 373 |
# File 'lib/etl/control/control.rb', line 371 def destination_types [:file, :database] end |
#destinations ⇒ Object
Get the defined destinations
311 312 313 |
# File 'lib/etl/control/control.rb', line 311 def destinations @destinations ||= [] end |
#post_processors ⇒ Object
Get an Array of post processors
335 336 337 |
# File 'lib/etl/control/control.rb', line 335 def post_processors @post_processors ||= [] end |
#pre_processors ⇒ Object
Get an Array of preprocessors
330 331 332 |
# File 'lib/etl/control/control.rb', line 330 def pre_processors @pre_processors ||= [] end |
#screens ⇒ Object
344 345 346 347 348 349 350 |
# File 'lib/etl/control/control.rb', line 344 def screens @screens ||= { :fatal => [], :error => [], :warn => [] } end |
#source_types ⇒ Object
367 368 369 |
# File 'lib/etl/control/control.rb', line 367 def source_types [:file, :database] end |
#sources ⇒ Object
Get the defined source
306 307 308 |
# File 'lib/etl/control/control.rb', line 306 def sources @sources ||= [] end |
#transforms ⇒ Object
Get an Array of all transforms for this control
340 341 342 |
# File 'lib/etl/control/control.rb', line 340 def transforms @transforms ||= [] end |
#validate ⇒ Object
Validate the control file
358 359 360 361 362 363 364 365 |
# File 'lib/etl/control/control.rb', line 358 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 |