lib/each_sql.rb in each_sql-0.3.1 vs lib/each_sql.rb in each_sql-0.4.0
- old
+ new
@@ -7,26 +7,23 @@
# Shortcut method for creating a Enumerable EachSQL object for the given input.
# @param[String] input Input script.
# @param[Symbol] The type of the input SQL script. :default, :mysql, and :oracle (or :plsql)
# @yield[String] Executable SQL statement or block.
-# @return[Array] Array of executable SQL statements and blocks.
+# @return[Enumerator] Enumerator of executable SQL statements and blocks.
def EachSQL input, type = :default
+ return enum_for(:EachSQL, input, type) unless block_given?
+
esql = EachSQL.new(type)
- ret = []
result = {}
process = lambda {
return if esql.empty?
result = esql.shift
sqls = result[:sqls]
sqls.each do |sql|
- if block_given?
- yield sql
- else
- ret << sql
- end
+ yield sql
end
}
input.to_s.each_line do |line|
case line
@@ -48,15 +45,9 @@
if !esql.empty?
process.call
end
if sql = result[:leftover]
- if block_given?
- yield sql
- else
- ret << sql
- end
+ yield sql
end
-
- ret
end