Skip to content

Commit

Permalink
Extract the logic closing the destinations
Browse files Browse the repository at this point in the history
This will be useful to dry #44.
  • Loading branch information
thbar committed Dec 23, 2017
1 parent fb2c4ba commit b370767
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/kiba/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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|
Expand All @@ -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
Expand Down

0 comments on commit b370767

Please sign in to comment.