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.
-
.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.
- #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
255 256 257 |
# File 'lib/etl/control/control.rb', line 255 def initialize(file) @file = file end |
Instance Attribute Details
#error_threshold ⇒ Object
Get the error threshold. Defaults to 100.
219 220 221 |
# File 'lib/etl/control/control.rb', line 219 def error_threshold @error_threshold end |
#file ⇒ Object (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_processors ⇒ Object
transforms ||= []
end
279 280 281 |
# File 'lib/etl/control/control.rb', line 279 def after_read_processors @after_read_processors ||= [] end |
#before_write_processors ⇒ Object
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 |
#dependencies ⇒ Object
Get a list of dependencies
260 261 262 |
# File 'lib/etl/control/control.rb', line 260 def dependencies @dependencies ||= [] end |
#destination_types ⇒ Object
322 323 324 |
# File 'lib/etl/control/control.rb', line 322 def destination_types [:file, :database] end |
#destinations ⇒ Object
Get the defined destinations
270 271 272 |
# File 'lib/etl/control/control.rb', line 270 def destinations @destinations ||= [] end |
#post_processors ⇒ Object
Get an Array of post processors
294 295 296 |
# File 'lib/etl/control/control.rb', line 294 def post_processors @post_processors ||= [] end |
#pre_processors ⇒ Object
Get an Array of preprocessors
289 290 291 |
# File 'lib/etl/control/control.rb', line 289 def pre_processors @pre_processors ||= [] end |
#source_types ⇒ Object
318 319 320 |
# File 'lib/etl/control/control.rb', line 318 def source_types [:file, :database] end |
#sources ⇒ Object
Get the defined source
265 266 267 |
# File 'lib/etl/control/control.rb', line 265 def sources @sources ||= [] end |
#transforms ⇒ Object
Get an Array of all transforms for this control
299 300 301 |
# File 'lib/etl/control/control.rb', line 299 def transforms @transforms ||= [] end |
#validate ⇒ Object
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 |