Class: Breathing::TerminalTable
- Inherits:
-
Object
- Object
- Breathing::TerminalTable
- Defined in:
- lib/breathing/terminal_table.rb
Instance Attribute Summary collapse
-
#last_id ⇒ Object
readonly
Returns the value of attribute last_id.
Instance Method Summary collapse
-
#initialize(table_name) ⇒ TerminalTable
constructor
A new instance of TerminalTable.
- #render(id: 1) ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(table_name) ⇒ TerminalTable
Returns a new instance of TerminalTable.
8 9 10 11 |
# File 'lib/breathing/terminal_table.rb', line 8 def initialize(table_name) @last_id = 1 @table_name = table_name end |
Instance Attribute Details
#last_id ⇒ Object (readonly)
Returns the value of attribute last_id.
6 7 8 |
# File 'lib/breathing/terminal_table.rb', line 6 def last_id @last_id end |
Instance Method Details
#render(id: 1) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 ⇒ Object
26 27 28 |
# File 'lib/breathing/terminal_table.rb', line 26 def rows @table.rows end |