Class: Middleman::PreviewServer::Checks::InterfaceIsAvailableOnSystem

Inherits:
BasicCheck
  • Object
show all
Defined in:
lib/middleman-core/preview_server/checks.rb

Overview

This validation fails if the user chooses to use an ip address which is not available on his/her system

Instance Method Summary collapse

Instance Method Details

#validate(information) ⇒ Object

Validate


48
49
50
51
52
53
# File 'lib/middleman-core/preview_server/checks.rb', line 48

def validate(information)
  return if information.bind_address.blank? || information.local_network_interfaces.include?(information.bind_address.to_s) || %w(0.0.0.0 ::).any? { |b| information.bind_address == b } || IPAddr.new('127.0.0.0/8').include?(information.bind_address.to_s)

  information.valid = false
  information.reason = format('Bind address "%s" is not available on your system. Please use one of %s', information.bind_address, information.local_network_interfaces.map { |i| %("#{i}") }.join(', '))
end