Class: Pwrake::HostMap
- Inherits:
-
Hash
- Object
- Hash
- Pwrake::HostMap
- Defined in:
- lib/pwrake/option/host_map.rb
Instance Attribute Summary collapse
-
#by_id ⇒ Object
readonly
Returns the value of attribute by_id.
-
#by_name ⇒ Object
readonly
Returns the value of attribute by_name.
Instance Method Summary collapse
- #group_core_weight ⇒ Object
- #group_hosts ⇒ Object
- #group_weight_sum ⇒ Object
- #host_count ⇒ Object
-
#initialize(arg = nil) ⇒ HostMap
constructor
A new instance of HostMap.
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_id ⇒ Object (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_name ⇒ Object (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_weight ⇒ Object
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_hosts ⇒ Object
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_sum ⇒ Object
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_count ⇒ Object
63 64 65 |
# File 'lib/pwrake/option/host_map.rb', line 63 def host_count @by_id.size end |