diff --git a/lib/kiba/runner.rb b/lib/kiba/runner.rb index 6ee8e80..e3fab74 100644 --- a/lib/kiba/runner.rb +++ b/lib/kiba/runner.rb @@ -13,8 +13,9 @@ def run(control) process_rows( to_instances(control.sources), to_instances(control.transforms, true), - to_instances(control.destinations) + destinations = to_instances(control.destinations) ) + close_destinations(destinations) # TODO: when I add post processes as class, I'll have to add a test to # make sure instantiation occurs after the main processing is done (#16) run_post_processes(control) @@ -28,6 +29,12 @@ def run_post_processes(control) to_instances(control.post_processes, true, false).each(&:call) end + def close_destinations(destinations) + destinations + .find_all { |d| d.respond_to?(:close) } + .each(&:close) + end + def process_rows(sources, transforms, destinations) sources.each do |source| source.each do |row| @@ -41,7 +48,6 @@ def process_rows(sources, transforms, destinations) end end end - destinations.find_all { |d| d.respond_to?(:close) }.each(&:close) end # not using keyword args because JRuby defaults to 1.9 syntax currently