Class: CapEC2::StatusTable

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/cap-ec2/status-table.rb

Instance Method Summary collapse

Methods included from Utils

contact_point, contact_point_mapping, #get_regions, #load_config, #project_tag, #roles_tag, #stages_tag, #tag_delimiter, #tag_value

Constructor Details

#initialize(instances) ⇒ StatusTable

Returns a new instance of StatusTable.



5
6
7
8
# File 'lib/cap-ec2/status-table.rb', line 5

def initialize(instances)
  @instances = instances
  output
end

Instance Method Details

#header_rowObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cap-ec2/status-table.rb', line 10

def header_row
  [
    bold("Num"),
    bold("Name"),
    bold("ID"),
    bold("Type"),
    bold("DNS"),
    bold("Zone"),
    bold("Roles"),
    bold("Stages")
  ]
end

#instance_to_row(instance, index) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cap-ec2/status-table.rb', line 38

def instance_to_row(instance, index)
  [
    sprintf("%02d:", index),
    green(tag_value(instance, 'Name') || ''),
    red(instance.instance_id),
    cyan(instance.instance_type),
    bold(blue(CapEC2::Utils.contact_point(instance))),
    magenta(instance.placement.availability_zone),
    yellow(tag_value(instance, roles_tag)),
    yellow(tag_value(instance, stages_tag))
  ]
end

#outputObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cap-ec2/status-table.rb', line 23

def output
  table = Terminal::Table.new(
    :style => {
      :border_x => "",
      :border_i => "",
      :border_y => ""
    }
  )
  table.add_row header_row
  @instances.each_with_index do |instance,index|
    table.add_row instance_to_row(instance, index)
  end
  puts table.to_s
end