class Ryakuzu::Ripper

Attributes

schema[R]

Public Class Methods

parse(filename) click to toggle source
# File lib/ryakuzu/schema_parsing/ripper.rb, line 26
def self.parse(filename)
  new.parse(filename).schema
end

Public Instance Methods

parse(filename) click to toggle source
# File lib/ryakuzu/schema_parsing/ripper.rb, line 6
def parse(filename)
  sexp = ::Ripper.sexp IO.read(filename)

  schema_commands = sexp[1][0][2][2]
  @schema = schema_commands.inject({}) do |s, command|
    next if command.length < 1
    command_name = command[1][1][1]

    if command_name == 'create_table'
      table_name = command[1][2][1][0][1][1][1].to_sym
      columns    = command[2][2].map { |i| i[4][1][0][1][1][1] }

      s.merge!(table_name => columns)
    end
    s
  end

  self
end