Class: DBA::DiagramPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/dba/diagram_printer.rb

Direct Known Subclasses

DBMLPrinter, DOTPrinter, PlantUMLPrinter

Instance Method Summary collapse

Constructor Details

#initialize(io = STDOUT) ⇒ DiagramPrinter

Returns a new instance of DiagramPrinter.



2
3
4
# File 'lib/dba/diagram_printer.rb', line 2

def initialize(io = STDOUT)
  @io = io
end

Instance Method Details



62
63
# File 'lib/dba/diagram_printer.rb', line 62

def print_column(name, type)
end


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dba/diagram_printer.rb', line 6

def print_diagram(database)
  print_start

  @primary_keys = {}

  table_names = database.tables

  table_names.each do |name|
    schema_hash = database.schema(name)

    print_table(name, schema_hash)
  end

  table_names.each do |table|
    database.foreign_key_list(table).each do |hash|
      column = hash.fetch(:columns).first

      other_table = hash.fetch(:table)

      other_column = @primary_keys.fetch(other_table)

      print_foreign_key(table, column, other_table, other_column)
    end
  end

  print_end
end


37
38
# File 'lib/dba/diagram_printer.rb', line 37

def print_end
end


65
66
# File 'lib/dba/diagram_printer.rb', line 65

def print_foreign_key(table, column, other_table, other_column)
end


34
35
# File 'lib/dba/diagram_printer.rb', line 34

def print_start
end


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dba/diagram_printer.rb', line 40

def print_table(name, schema_hash)
  print_table_start(name)

  schema_hash.each do |column_name, info_hash|
    column_type = info_hash[:type] || info_hash[:db_type]

    if info_hash[:primary_key]
      @primary_keys[name] = column_name
    end

    print_column(column_name, column_type)
  end

  print_table_end(name)
end


59
60
# File 'lib/dba/diagram_printer.rb', line 59

def print_table_end(name)
end


56
57
# File 'lib/dba/diagram_printer.rb', line 56

def print_table_start(name)
end