class Percheron::Formatters::Stack::Table

Attributes

queue[R]
stack[R]

Public Class Methods

new(stack) click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 8
def initialize(stack)
  @stack = stack
  @queue = Queue.new
end

Public Instance Methods

generate() click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 13
def generate
  Terminal::Table.new(title: title, headings: headings, rows: rows)
end

Private Instance Methods

headings() click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 25
def headings
  [
    'Unit',
    'ID',
    'Running?',
    'IP',
    'Ports',
    'Volumes',
    'Size',
    'Version'
  ]
end
process_queue!() click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 47
def process_queue!
  resp = []
  4.times.map do
    Thread.new { queue.size.times { resp << queue.pop(true) } }
  end.map(&:join)
  resp
end
queue_jobs() click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 43
def queue_jobs
  stack.units.map { |_, unit| queue << row_for(unit) }
end
row_for(unit) click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 55
def row_for(unit)
  [
    unit.name,
    unit.id,
    startable(unit),
    unit.ip,
    unit.ports.join(', '),
    unit.volumes.join("\n"),
    unit.image_size,
    version(unit)
  ]
end
rows() click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 38
def rows
  queue_jobs
  process_queue!
end
startable(unit) click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 72
def startable(unit)
  if unit.startable?
    unit.running? ? 'yes' : '-'
  else
    'n/a'
  end
end
title() click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 21
def title
  stack.name
end
version(unit) click to toggle source
# File lib/percheron/formatters/stack/table.rb, line 68
def version(unit)
  (unit.built_version == '0.0.0') ? '' : unit.built_version
end