Class: ServerSettings::HostCollection
- Inherits:
-
Array
- Object
- Array
- ServerSettings::HostCollection
- Defined in:
- lib/server_settings/host_collection.rb
Defined Under Namespace
Classes: InvalidHosts
Instance Method Summary collapse
-
#initialize(hosts, role_config) ⇒ HostCollection
constructor
A new instance of HostCollection.
- #with_format(format) ⇒ Object
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 |