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

Inherits:
BasicCheck
  • Object
show all
Defined in:
middleman-core/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

Parameters:

  • information (Information)

    The information to be validated


52
53
54
55
56
57
58
59
60
61
# File 'middleman-core/lib/middleman-core/preview_server/checks.rb', line 52

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 "%<bad_addr>s" is not available on your system. Please use one of %<good_addrs>s',
    bad_addr: information.bind_address,
    good_addrs: information.local_network_interfaces.map { |i| %("#{i}") }.join(', ')
  )
end