Class: Rubber::Configuration::RoleItem

Inherits:
Object
  • Object
show all
Defined in:
lib/rubber/instance.rb

Overview

The configuration for a single role contained in the list of roles in InstanceItem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ RoleItem

Returns a new instance of RoleItem.



155
156
157
158
# File 'lib/rubber/instance.rb', line 155

def initialize(name, options={})
  @name = name
  @options = options || {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



116
117
118
# File 'lib/rubber/instance.rb', line 116

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



116
117
118
# File 'lib/rubber/instance.rb', line 116

def options
  @options
end

Class Method Details

.expand_role_dependencies(roles, dependency_map, expanded = []) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rubber/instance.rb', line 118

def self.expand_role_dependencies(roles, dependency_map, expanded=[])
  roles = Array(roles)
  roles.each do |role|
    unless expanded.include?(role)
      expanded << role
      needed = dependency_map[role]
      expand_role_dependencies(needed, dependency_map, expanded)
    end
  end
  return expanded
end

.parse(str) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rubber/instance.rb', line 130

def self.parse(str)
  data = str.split(':');
  role = Rubber::Configuration::RoleItem.new(data[0])
  if data[1]
    data[1].split(';').each do |pair|
      p = pair.split('=')
      val = case p[1]
              when 'true' then true
              when 'false' then false
              else p[1] end
      role.options[p[0]] = val
    end
  end
  return role
end

Instance Method Details

#<=>(rhs) ⇒ Object



169
170
171
# File 'lib/rubber/instance.rb', line 169

def <=>(rhs)
  return @name <=> rhs.name
end

#eql?(rhs) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


160
161
162
# File 'lib/rubber/instance.rb', line 160

def eql?(rhs)
  rhs && @name == rhs.name && @options == rhs.options
end

#hashObject



165
166
167
# File 'lib/rubber/instance.rb', line 165

def hash()
  @name.hash
end

#to_sObject



146
147
148
149
150
151
152
153
# File 'lib/rubber/instance.rb', line 146

def to_s
  str = @name
  @options.each_with_index do |kv, i|
    str += (i == 0 ? ':' : ';')
    str += "#{kv[0]}=#{kv[1]}"
  end
  return str
end