Sha256: 9408e3c672bfef44ff2f8d9c01dd1474e2abf8fec688d49035ababe11e79ec66

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Percheron
  module Formatters
    module Stack
      class Table

        def initialize(stack)
          @stack = stack
        end

        def generate
          Terminal::Table.new(title: title, headings: headings, rows: rows)
        end

        private

          attr_reader :stack

          def title
            stack.name
          end

          def headings
            [
              'Container',
              'ID',
              'Running?',
              'Ports',
              'Volumes',
              'Version'
            ]
          end

          def rows
            stack.containers.map do |_, container|
              [
                container.name,
                container.id,
                startable(container),
                container.ports.join(', '),
                container.volumes.join(', '),
                (container.built_version == '0.0.0') ? '' : container.built_version
              ]
            end
          end

          def startable(container)
            if container.startable?
              container.running? ? 'yes' : '-'
            else
              'n/a'
            end
          end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
percheron-0.7.3 lib/percheron/formatters/stack/table.rb
percheron-0.7.2 lib/percheron/formatters/stack/table.rb
percheron-0.7.1 lib/percheron/formatters/stack/table.rb
percheron-0.7.0 lib/percheron/formatters/stack/table.rb