Class: GCE::Host::RoleData

Inherits:
Object
  • Object
show all
Defined in:
lib/gce/host/role_data.rb

Overview

Represents each role

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RoleData) initialize(role1, role2 = nil, role3 = nil)

Returns a new instance of RoleData



7
8
9
10
11
# File 'lib/gce/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/gce/host/role_data.rb', line 5

def role1
  @role1
end

- (Object) role2 (readonly)

Returns the value of attribute role2



5
6
7
# File 'lib/gce/host/role_data.rb', line 5

def role2
  @role2
end

- (Object) role3 (readonly)

Returns the value of attribute role3



5
6
7
# File 'lib/gce/host/role_data.rb', line 5

def role3
  @role3
end

Class Method Details

+ (Object) build(role)



13
14
15
16
# File 'lib/gce/host/role_data.rb', line 13

def self.build(role)
  role1, role2, role3 = role.split(Config.role_value_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

Parameters:

  • other (Object)


48
49
50
51
52
53
54
55
56
57
# File 'lib/gce/host/role_data.rb', line 48

def ==(other)
  case other
  when String
    self.role == other
  when GCE::Host::RoleData
    super(other)
  else
    false
  end
end

- (Object) inspect



59
60
61
# File 'lib/gce/host/role_data.rb', line 59

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

- (Boolean) match?(role1, role2 = nil, role3 = nil)

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
# File 'lib/gce/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”

Returns:

  • (String)

    something like “admin:jenkins:slave”



19
20
21
# File 'lib/gce/host/role_data.rb', line 19

def role
  @role ||= [role1, role2, role3].compact.reject(&:empty?).join(Config.role_value_delimiter)
end

- (Array) uppers

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

Returns:

  • (Array)

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



25
26
27
28
29
30
# File 'lib/gce/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