Class: EC2::Host::RoleData
- Inherits:
-
Object
- Object
- EC2::Host::RoleData
- Defined in:
- lib/ec2/host/role_data.rb
Overview
Represents each role
Instance Attribute Summary (collapse)
-
- (Object) role1
readonly
Returns the value of attribute role1.
-
- (Object) role2
readonly
Returns the value of attribute role2.
-
- (Object) role3
readonly
Returns the value of attribute role3.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) ==(other)
Equality.
-
- (RoleData) initialize(role1, role2 = nil, role3 = nil)
constructor
A new instance of RoleData.
- - (Object) inspect
- - (Boolean) match?(role1, role2 = nil, role3 = nil)
-
- (String) role
(also: #to_s)
Something like “admin:jenkins:slave”.
-
- (Array) uppers
Something like [“admin”, “admin:jenkins”, “admin:jenkins:slave”].
Constructor Details
- (RoleData) initialize(role1, role2 = nil, role3 = nil)
Returns a new instance of RoleData
7 8 9 10 11 |
# File 'lib/ec2/host/role_data.rb', line 7 def initialize(role1, role2 = nil, role3 = nil) @role1 = role1 @role2 = role2 @role3 = role3 end |
Instance Attribute Details
- (Object) role1 (readonly)
Returns the value of attribute role1
5 6 7 |
# File 'lib/ec2/host/role_data.rb', line 5 def role1 @role1 end |
- (Object) role2 (readonly)
Returns the value of attribute role2
5 6 7 |
# File 'lib/ec2/host/role_data.rb', line 5 def role2 @role2 end |
- (Object) role3 (readonly)
Returns the value of attribute role3
5 6 7 |
# File 'lib/ec2/host/role_data.rb', line 5 def role3 @role3 end |
Class Method Details
+ (Object) build(role)
13 14 15 16 |
# File 'lib/ec2/host/role_data.rb', line 13 def self.build(role) role1, role2, role3 = role.split(Config.role_tag_delimiter, 3) new(role1, role2, role3) end |
Instance Method Details
- (Object) ==(other)
Equality
Role::Data.new('admin') == Role::Data.new('admin') #=> true
Role::Data.new('admin', 'jenkin') == "admin:jenkins" #=> true
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ec2/host/role_data.rb', line 48 def ==(other) case other when String self.role == other when EC2::Host::RoleData super(other) else false end end |
- (Object) inspect
59 60 61 |
# File 'lib/ec2/host/role_data.rb', line 59 def inspect "\"#{to_s}\"" end |
- (Boolean) match?(role1, role2 = nil, role3 = nil)
32 33 34 35 36 37 38 39 40 |
# File 'lib/ec2/host/role_data.rb', line 32 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 |
- (String) role Also known as: to_s
Returns something like “admin:jenkins:slave”
19 20 21 |
# File 'lib/ec2/host/role_data.rb', line 19 def role @role ||= [role1, role2, role3].compact.reject(&:empty?).join(Config.role_tag_delimiter) end |
- (Array) uppers
Returns something like [“admin”, “admin:jenkins”, “admin:jenkins:slave”]
25 26 27 28 29 30 |
# File 'lib/ec2/host/role_data.rb', line 25 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 |