Class: ServerSettings::HostCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/server_settings/host_collection.rb

Defined Under Namespace

Classes: InvalidHosts

Instance Method Summary collapse

Constructor Details

#initialize(hosts, role_config) ⇒ HostCollection

Returns a new instance of HostCollection.



4
5
6
7
8
9
10
11
12
13
# File 'lib/server_settings/host_collection.rb', line 4

def initialize(hosts, role_config)
  @role_config = role_config
  unless hosts.kind_of?(Array)
    raise InvalidHosts, "hosts: #{hosts} is not array"
  end

  hosts.each do |host_exp|
    self.push Host.parse(host_exp)
  end
end

Instance Method Details

#with_format(format) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/server_settings/host_collection.rb', line 15

def with_format(format)
  self.map do |host|
    replacemap = @role_config
    replacemap['%host'] = host.host
    replacemap['%port'] = host.port if host.port
    replacemap.inject(format) do |string, mapping|
      string.gsub(*mapping)
    end
  end
end