Class: Claws::EC2::Presenter
- Inherits:
-
Object
- Object
- Claws::EC2::Presenter
show all
- Defined in:
- lib/claws/presenter/ec2.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(instance, options = {}) ⇒ Presenter
Returns a new instance of Presenter.
9
10
11
12
13
14
|
# File 'lib/claws/presenter/ec2.rb', line 9
def initialize(instance, options = {})
@ec2 = instance.extend(Claws::Support)
@roles = options[:roles] || []
@region = options[:region]
freeze
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/claws/presenter/ec2.rb', line 32
def method_missing(meth)
case meth
when :name
@ec2.send(:tags)['Name'] || 'N/A'
when @ec2.try(:tags) && @ec2.tags.has_key?(meth)
@ec2.tags[meth] || 'N/A'
else
begin
@ec2.send(meth)
rescue Exception
'N/A'
end
end
end
|
Instance Attribute Details
#roles ⇒ Object
20
21
22
|
# File 'lib/claws/presenter/ec2.rb', line 20
def roles
@roles.empty? ? 'N/A' : @roles.join(', ')
end
|
Instance Method Details
#region ⇒ Object
16
17
18
|
# File 'lib/claws/presenter/ec2.rb', line 16
def region
@region || 'N/A'
end
|
#security_groups ⇒ Object
28
29
30
|
# File 'lib/claws/presenter/ec2.rb', line 28
def security_groups
@ec2.try(:security_groups) ? @ec2.security_groups.map {|sg| "#{sg.id}: #{sg.name}"}.join(', ') : 'N/A'
end
|
24
25
26
|
# File 'lib/claws/presenter/ec2.rb', line 24
def tags
@ec2.try(:tags) ? @ec2.tags.select {|k,v| [k,v] unless k.downcase == 'name'}.map{|k,v| "#{k}: #{v}"}.join(', ') : 'N/A'
end
|