Class: Rails::Schema::Extractor::SchemaFileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/schema/extractor/schema_file_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_path = nil) ⇒ SchemaFileParser

Returns a new instance of SchemaFileParser.



14
15
16
17
# File 'lib/rails/schema/extractor/schema_file_parser.rb', line 14

def initialize(schema_path = nil)
  @schema_path = schema_path
  @views = Set.new
end

Instance Attribute Details

#viewsObject (readonly)

schema.rb does not declare SQL views, so this is always empty; the reader exists so SchemaFileParser and StructureSqlParser share an interface (see Rails::Schema.parse_schema).



12
13
14
# File 'lib/rails/schema/extractor/schema_file_parser.rb', line 12

def views
  @views
end

Instance Method Details

#parseObject



19
20
21
22
23
24
# File 'lib/rails/schema/extractor/schema_file_parser.rb', line 19

def parse
  path = resolve_path
  return {} unless path && File.exist?(path)

  parse_content(File.read(path))
end

#parse_content(content) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/rails/schema/extractor/schema_file_parser.rb', line 26

def parse_content(content)
  @tables = {}
  @current_table = nil
  @pk_type = nil
  @has_pk = true

  content.each_line { |line| process_line(line.strip) }

  @tables
end