Class: InstanceCollection
- Includes:
- Enumerable
- Defined in:
- lib/maws/instance_collection.rb
Instance Attribute Summary collapse
-
#members ⇒ Object
Returns the value of attribute members.
Instance Method Summary collapse
- #*(x) ⇒ Object
- #add(instance) ⇒ Object
- #alive ⇒ Object
- #aws ⇒ Object
- #each ⇒ Object
- #ebs ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(members = []) ⇒ InstanceCollection
constructor
A new instance of InstanceCollection.
- #matching(filters = {}) ⇒ Object
- #not_alive ⇒ Object
- #not_matching(filters) ⇒ Object
- #not_specified ⇒ Object
- #roles ⇒ Object
- #roles_in_order_of(roles_list) ⇒ Object
- #services ⇒ Object
-
#specified ⇒ Object
scopes.
- #with_approximate_status(status) ⇒ Object
- #with_role(role) ⇒ Object
- #with_service(service) ⇒ Object
- #with_zone(zone) ⇒ Object
- #without_role(role) ⇒ Object
- #zones ⇒ Object
Constructor Details
#initialize(members = []) ⇒ InstanceCollection
Returns a new instance of InstanceCollection.
6 7 8 |
# File 'lib/maws/instance_collection.rb', line 6 def initialize(members = []) @members = members.sort_by {|m| [m.region, m.zone.to_s, m.role.to_s, m.index || 1]} end |
Instance Attribute Details
#members ⇒ Object
Returns the value of attribute members.
4 5 6 |
# File 'lib/maws/instance_collection.rb', line 4 def members @members end |
Instance Method Details
#*(x) ⇒ Object
26 27 28 |
# File 'lib/maws/instance_collection.rb', line 26 def *(x) @members * x end |
#add(instance) ⇒ Object
10 11 12 |
# File 'lib/maws/instance_collection.rb', line 10 def add(instance) @members << instance end |
#alive ⇒ Object
67 68 69 |
# File 'lib/maws/instance_collection.rb', line 67 def alive self.matching(:alive? => true) end |
#aws ⇒ Object
63 64 65 |
# File 'lib/maws/instance_collection.rb', line 63 def aws self.matching(:groups => 'aws') end |
#each ⇒ Object
14 15 16 |
# File 'lib/maws/instance_collection.rb', line 14 def each @members.each {|m| yield m} end |
#ebs ⇒ Object
91 92 93 |
# File 'lib/maws/instance_collection.rb', line 91 def ebs with_service(:ebs) end |
#empty? ⇒ Boolean
18 19 20 |
# File 'lib/maws/instance_collection.rb', line 18 def empty? @members.empty? end |
#first ⇒ Object
22 23 24 |
# File 'lib/maws/instance_collection.rb', line 22 def first @members.first end |
#matching(filters = {}) ⇒ Object
30 31 32 |
# File 'lib/maws/instance_collection.rb', line 30 def matching(filters = {}) InstanceCollection.new(self.find_all {|i| i.matches?(filters)}) end |
#not_alive ⇒ Object
71 72 73 |
# File 'lib/maws/instance_collection.rb', line 71 def not_alive self.matching(:alive? => false) end |
#not_matching(filters) ⇒ Object
34 35 36 |
# File 'lib/maws/instance_collection.rb', line 34 def not_matching(filters) InstanceCollection.new(self.find_all {|i| !i.matches?(filters)}) end |
#not_specified ⇒ Object
59 60 61 |
# File 'lib/maws/instance_collection.rb', line 59 def not_specified self.not_matching(:groups => 'specified') end |
#roles ⇒ Object
42 43 44 |
# File 'lib/maws/instance_collection.rb', line 42 def roles map{|i| i.role}.uniq end |
#roles_in_order_of(roles_list) ⇒ Object
50 51 52 |
# File 'lib/maws/instance_collection.rb', line 50 def roles_in_order_of(roles_list) roles.sort_by {|r| roles_list.index(r)} end |
#services ⇒ Object
38 39 40 |
# File 'lib/maws/instance_collection.rb', line 38 def services self.map {|i| i.service}.uniq end |
#specified ⇒ Object
scopes
55 56 57 |
# File 'lib/maws/instance_collection.rb', line 55 def specified self.matching(:groups => 'specified') end |
#with_approximate_status(status) ⇒ Object
95 96 97 |
# File 'lib/maws/instance_collection.rb', line 95 def with_approximate_status(status) self.matching(:approximate_status => status) end |
#with_role(role) ⇒ Object
79 80 81 |
# File 'lib/maws/instance_collection.rb', line 79 def with_role(role) self.matching(:role => role) end |
#with_service(service) ⇒ Object
75 76 77 |
# File 'lib/maws/instance_collection.rb', line 75 def with_service(service) self.matching(:service => service.to_sym) end |
#with_zone(zone) ⇒ Object
83 84 85 |
# File 'lib/maws/instance_collection.rb', line 83 def with_zone(zone) self.matching(:zone => zone) end |
#without_role(role) ⇒ Object
87 88 89 |
# File 'lib/maws/instance_collection.rb', line 87 def without_role(role) self.not_matching(:role => role) end |
#zones ⇒ Object
46 47 48 |
# File 'lib/maws/instance_collection.rb', line 46 def zones map{|i| i.zone}.uniq end |