Class: ActualDbSchema::SchemaParser::SchemaCollector

Inherits:
Parser::AST::Processor
  • Object
show all
Defined in:
lib/actual_db_schema/schema_parser.rb

Overview

Internal class used to process the AST and collect schema information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchemaCollector

Returns a new instance of SchemaCollector.



23
24
25
26
# File 'lib/actual_db_schema/schema_parser.rb', line 23

def initialize
  super()
  @schema = {}
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



21
22
23
# File 'lib/actual_db_schema/schema_parser.rb', line 21

def schema
  @schema
end

Instance Method Details

#on_block(node) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/actual_db_schema/schema_parser.rb', line 28

def on_block(node)
  send_node, _args_node, body = *node

  if create_table_call?(send_node)
    table_name = extract_table_name(send_node)
    columns    = extract_columns(body)
    @schema[table_name] = columns if table_name
  end

  super
end

#on_send(node) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/actual_db_schema/schema_parser.rb', line 40

def on_send(node)
  _receiver, method_name, *args = *node
  if method_name == :create_table && args.any?
    table_name = extract_table_name(node)
    @schema[table_name] ||= {}
  end

  super
end