Class: Comana::HostSelector
- Inherits:
-
Object
- Object
- Comana::HostSelector
- Defined in:
- lib/comana/hostselector.rb
Defined Under Namespace
Classes: NoEntryError
Class Method Summary collapse
Instance Method Summary collapse
-
#groups ⇒ Object
Return all groups with sorted order.
-
#initialize(groups_hosts) ⇒ HostSelector
constructor
Argument ‘groups_hosts’ should be a hash; the keys are group name, and the value is the hostnames of the member.
-
#select_all ⇒ Object
Return all hosts included with sorted order.
-
#select_group(group) ⇒ Object
Return member hosts in indicated group.
Constructor Details
#initialize(groups_hosts) ⇒ HostSelector
Argument ‘groups_hosts’ should be a hash; the keys are group name, and the value is the hostnames of the member.
14 15 16 |
# File 'lib/comana/hostselector.rb', line 14 def initialize(groups_hosts) @groups_hosts = groups_hosts end |
Class Method Details
.load_file(file = Comana::ClusterSetting::DEFAULT_DATA_FILE) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/comana/hostselector.rb', line 18 def self.load_file(file = Comana::ClusterSetting::DEFAULT_DATA_FILE) #pp Comana::ClusterSetting::DEFAULT_DATA_FILE yaml = YAML.load_file(file) groups_hosts = {} yaml["groups"].each do |key, val| groups_hosts[key] = val["members"] end self.new(groups_hosts) end |
Instance Method Details
#groups ⇒ Object
Return all groups with sorted order.
40 41 42 |
# File 'lib/comana/hostselector.rb', line 40 def groups @groups_hosts.keys.sort end |
#select_all ⇒ Object
Return all hosts included with sorted order.
29 30 31 |
# File 'lib/comana/hostselector.rb', line 29 def select_all @groups_hosts.values.flatten.delete_if{|v| v == nil}.sort end |
#select_group(group) ⇒ Object
Return member hosts in indicated group.
34 35 36 37 |
# File 'lib/comana/hostselector.rb', line 34 def select_group(group) raise NoEntryError unless @groups_hosts.keys.include? group @groups_hosts[group] end |