class Breathing::TerminalTable

Attributes

last_id[R]

Public Class Methods

new(table_name) click to toggle source
# File lib/breathing/terminal_table.rb, line 8
def initialize(table_name)
  @last_id    = 1
  @table_name = table_name
end

Public Instance Methods

render(id: 1) click to toggle source
# File lib/breathing/terminal_table.rb, line 13
def render(id: 1)
  rows = Breathing::ChangeLog.where(table_name: @table_name).where("id >= ? ", id).order(:id)

  return if rows.size.zero?

  @table = Terminal::Table.new(title:    rows.first.table_name,
                               headings: rows.first.data_attributes.keys,
                               rows:     rows.map { |row| row.data_attributes.values })

  @last_id = rows.last.id
  @table.to_s
end
rows() click to toggle source
# File lib/breathing/terminal_table.rb, line 26
def rows
  @table.rows
end