Class: Middleman::PreviewServer::ServerInformation
- Inherits:
-
Object
- Object
- Middleman::PreviewServer::ServerInformation
- Defined in:
- middleman-core/lib/middleman-core/preview_server/server_information.rb
Overview
This class holds all information which the preview server needs to setup a listener
- server name
- bind address
- port
Furthermore it probes for a free tcp port, if the default one 4567 is not available.
Instance Attribute Summary collapse
-
#https ⇒ Object
writeonly
Sets the attribute https.
Instance Method Summary collapse
-
#bind_address ⇒ String
The bind address of server.
-
#handler ⇒ String
Make information of internal server class avaible to make debugging easier.
-
#https? ⇒ Boolean
Is https enabled?.
-
#information ⇒ Object
The information.
-
#initialize(options_hash = ::Middleman::EMPTY_HASH) ⇒ ServerInformation
constructor
A new instance of ServerInformation.
-
#listeners ⇒ Array
A list of listeners.
-
#port ⇒ Integer
The port on which the server should listen.
-
#reason ⇒ String
The reason why the information is NOT valid.
-
#server_name ⇒ String
The server name.
-
#site_addresses ⇒ Array
A list of site addresses.
-
#use(config) ⇒ Object
Use a middleman configuration to get information.
-
#valid? ⇒ TrueClass, FalseClass
Is the server information valid?.
Constructor Details
#initialize(options_hash = ::Middleman::EMPTY_HASH) ⇒ ServerInformation
Returns a new instance of ServerInformation.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 27 def initialize( = ::Middleman::EMPTY_HASH) @resolver = .fetch(:resolver, DnsResolver.new) @validator = .fetch(:validator, ServerInformationValidator.new) @network_interface_inventory = .fetch(:network_interface_inventory, NetworkInterfaceInventory.new) @tcp_port_prober = .fetch(:tcp_port_prober, TcpPortProber.new) @informations = [] @informations << AllInterfaces @informations << AllIpv4Interfaces @informations << AllIpv6Interfaces @informations << ServerNameIsIpInformation @informations << ServerNameInformation @informations << BindAddressInformation @informations << BindAddressAndServerNameInformation @informations << DefaultInformation end |
Instance Attribute Details
#https=(value) ⇒ Object (writeonly)
Sets the attribute https
25 26 27 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 25 def https=(value) @https = value end |
Instance Method Details
#bind_address ⇒ String
The bind address of server
120 121 122 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 120 def bind_address information.bind_address end |
#handler ⇒ String
Make information of internal server class avaible to make debugging easier. This can be used to log the class which was used to determine the preview server settings
85 86 87 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 85 def handler information.class.to_s end |
#https? ⇒ Boolean
Is https enabled?
150 151 152 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 150 def https? @https == true end |
#information ⇒ Object
The information
Is cached
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 47 def information return @information if @information # The `DefaultInformation`-class always returns `true`, so there's # always a klass available and find will never return nil listener_klass = informations.find { |l| l.matches? bind_address: @bind_address, server_name: @server_name } @information = listener_klass.new(bind_address: @bind_address, server_name: @server_name) @information.show_me_network_interfaces(network_interface_inventory) @information.resolve_me(resolver) @information.port = tcp_port_prober.port(@port) @information.validate_me(validator) @information end |
#listeners ⇒ Array
A list of listeners
145 146 147 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 145 def listeners information.listeners end |
#port ⇒ Integer
The port on which the server should listen
128 129 130 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 128 def port information.port end |
#reason ⇒ String
The reason why the information is NOT valid
104 105 106 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 104 def reason information.reason end |
#server_name ⇒ String
The server name
112 113 114 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 112 def server_name information.server_name end |
#site_addresses ⇒ Array
A list of site addresses
137 138 139 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 137 def site_addresses information.site_addresses end |
#use(config) ⇒ Object
Use a middleman configuration to get information
67 68 69 70 71 72 73 74 75 76 77 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 67 def use(config) @bind_address = config[:bind_address] @port = config[:port] @server_name = config[:server_name] @https = config[:https] config[:bind_address] = bind_address config[:port] = port config[:server_name] = server_name config[:https] = https? end |
#valid? ⇒ TrueClass, FalseClass
Is the server information valid?
This is used to output a helpful error message, which can be stored in
#reason
.
96 97 98 |
# File 'middleman-core/lib/middleman-core/preview_server/server_information.rb', line 96 def valid? information.valid? end |