Sha256: 25e79fec802fdb0e09fc998668fe71d61f532b14e2d1ae2034c2c22a8e783bc3

Contents?: true

Size: 801 Bytes

Versions: 3

Compression:

Stored size: 801 Bytes

Contents

module ActiveRecord
  module Annotate
    module Dumper
      class << self
        def dump(table_name, connection = ActiveRecord::Base.connection)
          string_io = StringIO.new
          dumper(connection).send(:table, table_name, string_io)
          
          process_annotation(string_io)
        end
        
      private
        def dumper(connection)
          ActiveRecord::SchemaDumper.send(:new, connection)
        end
        
        def process_annotation(string_io)
          string_io.string.split("\n").map do |line|
            line.tap do |line|
              # commenting out the line
              line[0] = '#'
              # replacing strings with symbols
              line.gsub!(/"(\w+)"/, ':\1')
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_record-annotate-0.2 lib/active_record/annotate/dumper.rb
active_record-annotate-0.1.1 lib/active_record/annotate/dumper.rb
active_record-annotate-0.1 lib/active_record/annotate/dumper.rb