Class: EC2::Host::RoleData

Inherits:
Struct
  • Object
show all
Defined in:
lib/ec2/host/role_data.rb,
lib/ec2/host/role_data.rb

Overview

Represents each role

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#role1Object

Returns the value of attribute role1

Returns:

  • (Object)

    the current value of role1



3
4
5
# File 'lib/ec2/host/role_data.rb', line 3

def role1
  @role1
end

#role2Object

Returns the value of attribute role2

Returns:

  • (Object)

    the current value of role2



3
4
5
# File 'lib/ec2/host/role_data.rb', line 3

def role2
  @role2
end

#role3Object

Returns the value of attribute role3

Returns:

  • (Object)

    the current value of 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

Parameters:

  • other (Object)


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

#inspectObject



55
56
57
# File 'lib/ec2/host/role_data.rb', line 55

def inspect
  "\"#{to_s}\""
end

#match?(role1, role2 = nil, role3 = nil) ⇒ Boolean

Returns:

  • (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

#roleString Also known as: to_s

Returns something like “admin:jenkins:slave”.

Returns:

  • (String)

    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

#uppersArray

Returns something like [“admin”, “admin:jenkins”, “admin:jenkins:slave”].

Returns:

  • (Array)

    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