# A pattern extraction
class EmptyDataBreaker
# Eklas should be the kind of exception you want to raise
def initialize(eklas)
@eklas = eklas
end
# Call this with an included block, it will
# raise your given exception if the results are empty
def run(*args, &block)
result = block.call(*args)
raise @eklas if result.blank?
return result
end
end
# Used as follows
breaker = EmptyDataBreaker.new(NoDataException)
begin
result = breaker.run { ... }
result2 = breaker.run { ... }
return result2
rescue NoDataException
end