Module: Kontena::Cli::TableGenerator::Helper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



17
18
19
20
21
# File 'lib/kontena/cli/table_generator.rb', line 17

def self.included(base)
  if base.respond_to?(:option)
    base.option ['-q', '--quiet'], :flag, "Output the identifying column only"
  end
end

Instance Method Details

#generate_table(array, fields = nil, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/kontena/cli/table_generator.rb', line 27

def generate_table(array, fields = nil, &block)
  fields ||= self.fields if self.respond_to?(:fields)
  table_generator.new(
    array,
    fields,
    row_format_proc: block_given? ? block.to_proc : nil,
    header_format_proc: lambda { |item| pastel.bold(item.to_s.upcase) },
    render_options: self.respond_to?(:render_options) ? DEFAULT_RENDER_OPTS.merge(self.render_options) : DEFAULT_RENDER_OPTS
  ).render
end


38
39
40
41
# File 'lib/kontena/cli/table_generator.rb', line 38

def print_table(array, fields = nil, &block)
  output = generate_table(array, fields, &block)
  puts output unless output.strip.empty?
end

#table_generatorObject



23
24
25
# File 'lib/kontena/cli/table_generator.rb', line 23

def table_generator
  Kontena::Cli::TableGenerator
end