Class: Webpacker::DevServer

Inherits:
Object
  • Object
show all
Defined in:
lib/webpacker/dev_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DevServer

Returns a new instance of DevServer.


8
9
10
# File 'lib/webpacker/dev_server.rb', line 8

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


6
7
8
# File 'lib/webpacker/dev_server.rb', line 6

def config
  @config
end

Instance Method Details

#hostObject


32
33
34
# File 'lib/webpacker/dev_server.rb', line 32

def host
  fetch(:host)
end

#host_with_portObject


53
54
55
# File 'lib/webpacker/dev_server.rb', line 53

def host_with_port
  "#{host}:#{port}"
end

#hot_module_replacing?Boolean

Returns:

  • (Boolean)

23
24
25
26
27
28
29
30
# File 'lib/webpacker/dev_server.rb', line 23

def hot_module_replacing?
  case fetch(:hmr)
  when true, "true"
    true
  else
    false
  end
end

#https?Boolean

Returns:

  • (Boolean)

40
41
42
43
44
45
46
47
# File 'lib/webpacker/dev_server.rb', line 40

def https?
  case fetch(:https)
  when true, "true"
    true
  else
    false
  end
end

#portObject


36
37
38
# File 'lib/webpacker/dev_server.rb', line 36

def port
  fetch(:port)
end

#pretty?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/webpacker/dev_server.rb', line 57

def pretty?
  fetch(:pretty)
end

#protocolObject


49
50
51
# File 'lib/webpacker/dev_server.rb', line 49

def protocol
  https? ? "https" : "http"
end

#running?Boolean

Returns:

  • (Boolean)

12
13
14
15
16
17
18
19
20
21
# File 'lib/webpacker/dev_server.rb', line 12

def running?
  if config.dev_server.present?
    Socket.tcp(host, port, connect_timeout: connect_timeout).close
    true
  else
    false
  end
rescue
  false
end