Sha256: e5fee4af69cf6bce2871caa87bc4bdbc81b8dc509b3ad03f3dfd579cca27a6ee

Contents?: true

Size: 1.14 KB

Versions: 75

Compression:

Stored size: 1.14 KB

Contents

class String
  def delete_create_table(name)
    new_def = []
    in_block = false

    self.each_line do |line|
      if line =~ /\A\s*create_table\s+"#{name}"/
        in_block = true
      elsif in_block and line =~ /\A\s*end\s*\Z/
        in_block = false
      elsif not in_block
        new_def << line
      end
    end

    new_def = new_def.join
    raise 'must not happen' if new_def =~ /^\s*create_table\s+"#{name}"/m
    new_def.delete_add_index(name)
  end

  def delete_add_index(name, columns = nil)
    new_def = []
    in_block = false

    args = name.inspect
    args << ',\\s*\\[' + columns.map {|i| i.inspect }.join(',\\s*') + '\\]' if columns

    self.each_line do |line|
      if line !~ /\A\s*add_index\s+#{args}/
        new_def << line
      end
    end

    new_def = new_def.join
    raise 'must not happen' if new_def =~ /^\s*add_index\s+#{args}/m
    new_def
  end

  def gsub_surely(pattern, replace)
    old_str = self.dup
    new_str = self.gsub(pattern, replace)
    raise 'must not happen' if old_str == new_str
    new_str
  end

  def delete_empty_lines
    self.each_line.select {|line|
      line !~ /\A\s*\Z/
    }.join
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
ridgepole-0.6.1.beta spec/string_ext.rb
ridgepole-0.6.0 spec/string_ext.rb
ridgepole-0.6.0.beta5 spec/string_ext.rb
ridgepole-0.6.0.beta4 spec/string_ext.rb
ridgepole-0.5.3.beta4 spec/string_ext.rb
ridgepole-0.6.0.beta3 spec/string_ext.rb
ridgepole-0.6.0.beta2 spec/string_ext.rb
ridgepole-0.6.0.beta spec/string_ext.rb
ridgepole-0.5.3.beta2 spec/string_ext.rb
ridgepole-0.5.3.beta spec/string_ext.rb
ridgepole-0.5.2 spec/string_ext.rb
ridgepole-0.5.2.beta6 spec/string_ext.rb
ridgepole-0.5.2.beta5 spec/string_ext.rb
ridgepole-0.5.2.beta4 spec/string_ext.rb
ridgepole-0.5.2.beta3 spec/string_ext.rb
ridgepole-0.5.2.beta2 spec/string_ext.rb
ridgepole-0.5.2.beta spec/string_ext.rb
ridgepole-0.5.1 spec/string_ext.rb
ridgepole-0.5.1.beta3 spec/string_ext.rb
ridgepole-0.5.1.beta2 spec/string_ext.rb