class Middleman::PreviewServer::AllInterfaces

This one is used if no bind address and no server name is given

Public Class Methods

matches?(opts={}) click to toggle source
# File lib/middleman-core/preview_server/information.rb, line 103
def self.matches?(opts={})
  opts[:bind_address].blank? && opts[:server_name].blank?
end
new(*args) click to toggle source
# File lib/middleman-core/preview_server/information.rb, line 97
def initialize(*args)
  super

  after_init
end

Public Instance Methods

resolve_me(resolver) click to toggle source

Resolve ips

# File lib/middleman-core/preview_server/information.rb, line 108
def resolve_me(resolver)
  hostname          = ServerHostname.new(Socket.gethostname)
  hostname_ips      = resolver.ips_for(hostname)
  network_interface = ServerIpAddress.new(Array(local_network_interfaces).first)
  resolved_name     = ServerHostname.new(resolver.names_for(network_interface).first)

  if includes_array? local_network_interfaces, hostname_ips
    @server_name = hostname
    @site_addresses << hostname

    network_interface = ServerIpAddress.new((local_network_interfaces & hostname_ips).first)
  elsif RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
    @server_name = hostname
    @site_addresses << hostname
  elsif !resolved_name.blank?
    @server_name = resolved_name
    @site_addresses << resolved_name
  else
    @server_name = network_interface
  end

  @site_addresses << network_interface

  self
end

Private Instance Methods

after_init() click to toggle source
# File lib/middleman-core/preview_server/information.rb, line 140
def after_init
  @listeners << ServerIpAddress.new('::')
  @listeners << ServerIpAddress.new('0.0.0.0')
end
includes_array?(a, b) click to toggle source
# File lib/middleman-core/preview_server/information.rb, line 136
def includes_array?(a, b)
  !(a & b).empty?
end