Class: RubyPgExtras::TableInfoPrint

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pg_extras/table_info_print.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(data) ⇒ Object



7
8
9
# File 'lib/ruby_pg_extras/table_info_print.rb', line 7

def self.call(data)
  new.call(data)
end

Instance Method Details

#call(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_pg_extras/table_info_print.rb', line 11

def call(data)
  rows = data.map do |el|
    [
      el.fetch(:table_name),
      el.fetch(:table_size),
      el.fetch(:table_cache_hit),
      el.fetch(:indexes_cache_hit),
      el.fetch(:estimated_rows),
      el.fetch(:sequential_scans),
      el.fetch(:indexes_scans)
    ]
  end

  puts Terminal::Table.new(
    headings: [
      "Table name",
      "Table size",
      "Table cache hit",
      "Indexes cache hit",
      "Estimated rows",
      "Sequential scans",
      "Indexes scans"
    ],
    title: title,
    rows: rows
  )
end