lib/niceql.rb in niceql-0.1.21 vs lib/niceql.rb in niceql-0.1.22
- old
+ new
@@ -187,9 +187,20 @@
# clear all spaces before newlines, and all whitespaces before string end
sql.tap{ |slf| slf.gsub!( /\s+\n/, "\n" ) }.tap{ |slf| slf.gsub!(/\s+\z/, '') }
end
+ def self.prettify_multiple( sql_multi, colorize = true )
+ sql_multi.split( /(?>#{SQL_COMMENTS})|(\;)/ ).inject(['']) { |queries, pattern|
+ queries.last << pattern
+ queries << '' if pattern == ';'
+ queries
+ }.map!{ |sql|
+ # we were splitting by comments and ;, so if next sql start with comment we've got a misplaced \n\n
+ sql.match?(/\A\s+\z/) ? nil : prettify_sql( sql, colorize )
+ }.compact.join("\n\n")
+ end
+
private
def self.indent_multiline( verb, indent )
#
if verb.match?(/.\s*\n\s*./)
verb.lines.map!{|ln| "#{' ' * indent}" + ln}.join("\n")