Sha256: 135d2bf1e873b00be8546340c6cb982b78572dc6459e8094423a659b0ec44971
Contents?: true
Size: 664 Bytes
Versions: 2
Compression:
Stored size: 664 Bytes
Contents
require 'ripper' module Ryakuzu class Ripper attr_reader :schema 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 def self.parse(filename) new.parse(filename).schema end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ryakuzu-0.3.0 | lib/ryakuzu/schema_parsing/ripper.rb |
ryakuzu-0.2.6 | lib/ryakuzu/ripper.rb |