Class: EC2::Host::RoleData
- Inherits:
-
Struct
- Object
- Struct
- EC2::Host::RoleData
- Defined in:
- lib/ec2/host/role_data.rb,
lib/ec2/host/role_data.rb
Overview
Represents each role
Instance Attribute Summary collapse
-
#role1 ⇒ Object
Returns the value of attribute role1.
-
#role2 ⇒ Object
Returns the value of attribute role2.
-
#role3 ⇒ Object
Returns the value of attribute role3.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
Equality.
- #inspect ⇒ Object
- #match?(role1, role2 = nil, role3 = nil) ⇒ Boolean
-
#role ⇒ String
(also: #to_s)
Something like “admin:jenkins:slave”.
-
#uppers ⇒ Array
Something like [“admin”, “admin:jenkins”, “admin:jenkins:slave”].
Instance Attribute Details
#role1 ⇒ Object
Returns the value of attribute role1
3 4 5 |
# File 'lib/ec2/host/role_data.rb', line 3 def role1 @role1 end |
#role2 ⇒ Object
Returns the value of attribute role2
3 4 5 |
# File 'lib/ec2/host/role_data.rb', line 3 def role2 @role2 end |
#role3 ⇒ Object
Returns the value of attribute role3
3 4 5 |
# File 'lib/ec2/host/role_data.rb', line 3 def role3 @role3 end |
Class Method Details
.initialize(role) ⇒ Object
9 10 11 12 |
# File 'lib/ec2/host/role_data.rb', line 9 def self.initialize(role) role1, role2, role3 = role.split(Config.role_tag_delimiter) self.new(role1, role2, role3) end |
Instance Method Details
#==(other) ⇒ Object
Equality
Role::Data.new('admin') == Role::Data.new('admin') #=> true
Role::Data.new('admin', 'jenkin') == "admin:jenkins" #=> true
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ec2/host/role_data.rb', line 44 def ==(other) case other when String self.role == other when EC2::Host::RoleData super(other) else false end end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/ec2/host/role_data.rb', line 55 def inspect "\"#{to_s}\"" end |
#match?(role1, role2 = nil, role3 = nil) ⇒ Boolean
28 29 30 31 32 33 34 35 36 |
# File 'lib/ec2/host/role_data.rb', line 28 def match?(role1, role2 = nil, role3 = nil) if role3 role1 == self.role1 and role2 == self.role2 and role3 == self.role3 elsif role2 role1 == self.role1 and role2 == self.role2 else role1 == self.role1 end end |
#role ⇒ String Also known as: to_s
Returns something like “admin:jenkins:slave”.
15 16 17 |
# File 'lib/ec2/host/role_data.rb', line 15 def role @role ||= [role1, role2, role3].compact.reject(&:empty?).join(Config.role_tag_delimiter) end |
#uppers ⇒ Array
Returns something like [“admin”, “admin:jenkins”, “admin:jenkins:slave”].
21 22 23 24 25 26 |
# File 'lib/ec2/host/role_data.rb', line 21 def uppers uppers = [RoleData.new(role1)] uppers << RoleData.new(role1, role2) if role2 and !role2.empty? uppers << RoleData.new(role1, role2, role3) if role3 and !role3.empty? uppers end |