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 |
# File 'lib/comana/hostselector.rb', line 18 def self.load_file(file = 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.
39 40 41 |
# File 'lib/comana/hostselector.rb', line 39 def groups @groups_hosts.keys.sort end |
#select_all ⇒ Object
Return all hosts included with sorted order.
28 29 30 |
# File 'lib/comana/hostselector.rb', line 28 def select_all @groups_hosts.values.flatten.delete_if{|v| v == nil}.sort end |
#select_group(group) ⇒ Object
Return member hosts in indicated group.
33 34 35 36 |
# File 'lib/comana/hostselector.rb', line 33 def select_group(group) raise NoEntryError unless @groups_hosts.keys.include? group @groups_hosts[group] end |