Class: Ahnnotate::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/ahnnotate/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Table

Returns a new instance of Table.



8
9
10
11
12
# File 'lib/ahnnotate/table.rb', line 8

def initialize(**args)
  args.each do |key, value|
    public_send("#{key}=", value)
  end
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



4
5
6
# File 'lib/ahnnotate/table.rb', line 4

def columns
  @columns
end

#foreign_keysObject

Returns the value of attribute foreign_keys.



6
7
8
# File 'lib/ahnnotate/table.rb', line 6

def foreign_keys
  @foreign_keys
end

#indexesObject

Returns the value of attribute indexes.



5
6
7
# File 'lib/ahnnotate/table.rb', line 5

def indexes
  @indexes
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ahnnotate/table.rb', line 3

def name
  @name
end

Instance Method Details

#string(comment:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ahnnotate/table.rb', line 14

def string(comment:)
  tabularizer =
    Function::Tabularize.new(
      prefix: "#{comment}   ",
      cell_divider: "    "
    )

  output = StringIO.new
  output.puts "#{comment} == Schema Information"
  output.puts comment
  output.puts "#{comment} Table name: #{@name}"
  output.puts comment
  output.print tabularizer.call(columns, [:name, :type, :details])
  output.puts comment

  if indexes.any?
    output.puts "#{comment} Indexes:"
    output.puts comment
    output.print tabularizer.call(indexes, [:name, :presentable_columns, :presentable_unique, :comment])
    output.puts comment
  end

  if foreign_keys.any?
    output.puts "#{comment} Foreign keys:"
    output.puts comment
    output.puts tabularizer.call(foreign_keys, [:from, :to, :name])
    output.puts comment
  end

  output.string
end