Class: Middleman::PreviewServer::BasicInformation

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

Overview

Basic information class to wrap common behaviour

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BasicInformation

Create instance

Parameters:

  • bind_address (String)

    The bind address of the server

  • server_name (String)

    The name of the server

  • port (Integer)

    The port to listen on



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/middleman-core/preview_server/information.rb', line 30

def initialize(opts={})
  @bind_address = ServerIpAddress.new(opts[:bind_address])
  @server_name  = ServerHostname.new(opts[:server_name])
  @port         = opts[:port]
  @valid        = true

  @site_addresses = []
  @listeners = []
  @checks = []

  # This needs to be check for each use case. Otherwise `Webrick` will
  # complain about that.
  @checks << Checks::InterfaceIsAvailableOnSystem.new
end

Instance Attribute Details

#bind_addressObject

Returns the value of attribute bind_address



17
18
19
# File 'lib/middleman-core/preview_server/information.rb', line 17

def bind_address
  @bind_address
end

#listenersObject (readonly)

Returns the value of attribute listeners



18
19
20
# File 'lib/middleman-core/preview_server/information.rb', line 18

def listeners
  @listeners
end

#portObject

Returns the value of attribute port



17
18
19
# File 'lib/middleman-core/preview_server/information.rb', line 17

def port
  @port
end

#reasonObject

Returns the value of attribute reason



17
18
19
# File 'lib/middleman-core/preview_server/information.rb', line 17

def reason
  @reason
end

#server_nameObject

Returns the value of attribute server_name



17
18
19
# File 'lib/middleman-core/preview_server/information.rb', line 17

def server_name
  @server_name
end

#site_addressesObject (readonly)

Returns the value of attribute site_addresses



18
19
20
# File 'lib/middleman-core/preview_server/information.rb', line 18

def site_addresses
  @site_addresses
end

#validObject

Returns the value of attribute valid



17
18
19
# File 'lib/middleman-core/preview_server/information.rb', line 17

def valid
  @valid
end

Instance Method Details

#local_network_interfacesObject

Default is to get all network interfaces



71
72
73
# File 'lib/middleman-core/preview_server/information.rb', line 71

def local_network_interfaces
  network_interfaces_inventory.nil? ? [] : network_interfaces_inventory.network_interfaces(:all)
end

#resolve_meObject



58
59
60
# File 'lib/middleman-core/preview_server/information.rb', line 58

def resolve_me(*)
  fail NoMethodError
end

#show_me_network_interfaces(inventory) ⇒ Object

Get network information

Parameters:

  • inventory (#network_interfaces)

    Get list of available network interfaces



66
67
68
# File 'lib/middleman-core/preview_server/information.rb', line 66

def show_me_network_interfaces(inventory)
  @network_interfaces_inventory = inventory
end

#valid?Boolean

Is the given information valid?

Returns:

  • (Boolean)


46
47
48
# File 'lib/middleman-core/preview_server/information.rb', line 46

def valid?
  valid == true
end

#validate_me(validator) ⇒ Object

Pass "self" to validator

Parameters:

  • validator (#validate)

    The validator



54
55
56
# File 'lib/middleman-core/preview_server/information.rb', line 54

def validate_me(validator)
  validator.validate self, checks
end