Class: Edgestitch::Mysql::StructureConstraintOrderMunger

Inherits:
Object
  • Object
show all
Defined in:
lib/edgestitch/mysql/structure_constraint_order_munger.rb

Class Method Summary collapse

Class Method Details

.munge(sql) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/edgestitch/mysql/structure_constraint_order_munger.rb', line 8

def munge(sql)
  start_idx = end_idx = nil
  lines = sql.split("\n")
  lines.each_with_index do |line, idx|
    if line =~ /^\s*CONSTRAINT\b/
      start_idx = idx if start_idx.nil?
    elsif start_idx
      end_idx = idx - 1
      unless end_idx == start_idx
        lines[start_idx..end_idx] = order_and_commafy(lines[start_idx..end_idx])
      end
      start_idx = end_idx = nil
    end
  end
  lines.join("\n")
end