Class: RBoss::TableBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rboss/view/table_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TableBuilder

Returns a new instance of TableBuilder.



26
27
28
29
# File 'lib/rboss/view/table_builder.rb', line 26

def initialize(config)
  @config = config
  add_name_column if config[:scan]
end

Instance Method Details

#add_name_column(name = 'Name') ⇒ Object



31
32
33
# File 'lib/rboss/view/table_builder.rb', line 31

def add_name_column(name = 'Name')
  @name_column = name
end

#build_tableObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rboss/view/table_builder.rb', line 39

def build_table
  if @name_column
    @config[:header] ||= []
    @config[:header] = [] if @only_name
    @config[:header] = [@name_column] + @config[:header]
  end

  if @config[:aliases]
    aliases = @config[:aliases]
    aliases = [:name] + aliases if @name_column
    @config[:aliases] = aliases
  end

  builder = Yummi::TableBuilder::new(@config).defaults
  
  builder.repositories[:row_colorizers] << RBoss::HealthCheckers
  builder.repositories[:colorizers] << RBoss::Colorizers
  builder.repositories[:formatters] << RBoss::Formatters

  table = builder.build_table

  table.format_null :with => 'undefined'
  table.colorize_null :with => :red

  table.colorize :name, :with => "bold.white" if @name_column

  table
end

#show_only_nameObject



35
36
37
# File 'lib/rboss/view/table_builder.rb', line 35

def show_only_name
  @only_name = true
end