Class: Skeema::Ripper
- Inherits:
-
Object
- Object
- Skeema::Ripper
- Defined in:
- lib/skeema/ripper.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.parse(filename) ⇒ Object
34 35 36 |
# File 'lib/skeema/ripper.rb', line 34 def self.parse(filename) new.parse(filename).schema end |
Instance Method Details
#parse(filename) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/skeema/ripper.rb', line 5 def parse(filename) sexp = ::Ripper.sexp IO.read(filename) # yay, magic! schema_commands = sexp[1][0][2][2] @schema = schema_commands.inject({}) do |s, command| 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].each.map do |col_command| col_command[4][1][0][1][1][1].to_sym end s.merge!(table_name => columns) end end s end self end |
#schema ⇒ Object
30 31 32 |
# File 'lib/skeema/ripper.rb', line 30 def schema @schema end |