Class: Claws::Report::EC2

Inherits:
Object
  • Object
show all
Includes:
CommandLineReporter
Defined in:
lib/claws/report/ec2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, instances) ⇒ EC2

Returns a new instance of EC2.



10
11
12
13
# File 'lib/claws/report/ec2.rb', line 10

def initialize config, instances
  self.config = config
  self.instances = instances
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/claws/report/ec2.rb', line 6

def config
  @config
end

#instancesObject

Returns the value of attribute instances.



6
7
8
# File 'lib/claws/report/ec2.rb', line 6

def instances
  @instances
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/claws/report/ec2.rb', line 15

def run
  table :border => true do
    row :header => true do
      column 'Choice', :width => 6, :color => 'blue', :bold => true, :align => 'right'

      self.config.ec2.fields.each do |field, properties|
        text = properties['title'] || field
        width = properties['width'] || nil
        column text, :width => width, :color => 'blue', :bold => true
      end
    end

    choice = 0

    self.instances.each do |i|
      color = case i.status
              when :running
                'green'
              when :stopped
                'red'
              else
                'white'
              end

      row color: 'white' do
        column choice

        self.config.ec2.fields.each do |field, properties|
          props = ( field == 'status' ) ? {:color => color} : {}
          field_alias = field == 'id' ? 'instance_id' : field  # This makes 1.8.7 not spit out a warning
          column i.send( field_alias ), props
        end
      end

      choice += 1
    end
  end
end