Class: Pwrake::HostMap

Inherits:
Hash
  • Object
show all
Defined in:
lib/pwrake/option/host_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ HostMap



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pwrake/option/host_map.rb', line 41

def initialize(arg=nil)
  @host_map = {}
  @by_id = []
  @by_name = {}
  require "socket"
  case arg
  when /\.yaml$/
    read_yaml(arg)
  when String
    read_host(arg)
  when Integer
    parse_hosts(["localhost #{arg}"])
  when NilClass
    parse_hosts(["localhost 1"])
  else
    raise ArgumentError, "arg=#{arg.inspect}"
    #@num_threads = 1 if !@num_threads
    #@core_list = ['localhost'] * @num_threads
  end
end

Instance Attribute Details

#by_idObject (readonly)

Returns the value of attribute by_id.



61
62
63
# File 'lib/pwrake/option/host_map.rb', line 61

def by_id
  @by_id
end

#by_nameObject (readonly)

Returns the value of attribute by_name.



61
62
63
# File 'lib/pwrake/option/host_map.rb', line 61

def by_name
  @by_name
end

Instance Method Details

#group_core_weightObject



75
76
77
78
79
80
81
# File 'lib/pwrake/option/host_map.rb', line 75

def group_core_weight
  a = []
  self.each do |sub,list|
    list.each{|h| (a[h.group] ||= []) << h.weight}
  end
  a
end

#group_hostsObject



67
68
69
70
71
72
73
# File 'lib/pwrake/option/host_map.rb', line 67

def group_hosts
  a = []
  self.each do |sub,list|
    list.each{|h| (a[h.group] ||= []) << h.name}
  end
  a
end

#group_weight_sumObject



83
84
85
86
87
88
89
# File 'lib/pwrake/option/host_map.rb', line 83

def group_weight_sum
  a = []
  self.each do |sub,list|
    list.each{|h| a[h.group] = (a[h.group]||0) + h.weight}
  end
  a
end

#host_countObject



63
64
65
# File 'lib/pwrake/option/host_map.rb', line 63

def host_count
  @by_id.size
end